Revert "Server unicast option support"
authorSteven Barth <steven@midlink.org>
Mon, 30 Dec 2013 17:45:45 +0000 (18:45 +0100)
committerSteven Barth <steven@midlink.org>
Mon, 30 Dec 2013 17:45:45 +0000 (18:45 +0100)
This reverts commit 348cbc2efee1281c3b39e705114f44eca72a8247.

Avoid too much bloat for rarely useful functionality

src/dhcpv6.c
src/odhcp6c.c
src/odhcp6c.h

index 9bc03ea55fafb8409434f0ef9c68f9c641fb3bf9..42e512161161ae43cdab56927c1e1f1fadf1645f 100644 (file)
@@ -26,7 +26,6 @@
 #include <sys/time.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <arpa/inet.h>
 #include <netinet/in.h>
 
 #include <net/if.h>
@@ -102,8 +101,6 @@ static int64_t t1 = 0, t2 = 0, t3 = 0;
 static int request_prefix = -1;
 static enum odhcp6c_ia_mode na_mode = IA_MODE_NONE, pd_mode = IA_MODE_NONE;
 static bool accept_reconfig = false;
-// Server unicast address
-static struct in6_addr server_addr = IN6ADDR_ANY_INIT;
 
 // Reconfigure key
 static uint8_t reconf_key[16];
@@ -166,7 +163,6 @@ int init_dhcpv6(const char *ifname, int request_pd, int sol_timeout)
                        htons(DHCPV6_OPT_SIP_SERVER_A),
                        htons(DHCPV6_OPT_DNS_SERVERS),
                        htons(DHCPV6_OPT_DNS_DOMAIN),
-                       htons(DHCPV6_OPT_UNICAST),
                        htons(DHCPV6_OPT_NTP_SERVER),
                        htons(DHCPV6_OPT_AFTR_NAME),
                        htons(DHCPV6_OPT_PD_EXCLUDE),
@@ -374,29 +370,7 @@ static void dhcpv6_send(enum dhcpv6_msg type, uint8_t trid[3], uint32_t ecs)
                0, ALL_DHCPV6_RELAYS, ifindex};
        struct msghdr msg = {&srv, sizeof(srv), iov, cnt, NULL, 0, 0};
 
-       switch (type) {
-       case DHCPV6_MSG_REQUEST:
-       case DHCPV6_MSG_RENEW:
-       case DHCPV6_MSG_RELEASE:
-       case DHCPV6_MSG_DECLINE:
-               if (!IN6_IS_ADDR_UNSPECIFIED(&server_addr) &&
-                       odhcp6c_addr_in_scope(&server_addr)) {
-                       srv.sin6_addr = server_addr;
-                       if (!IN6_IS_ADDR_LINKLOCAL(&server_addr))
-                               srv.sin6_scope_id = 0;
-               }
-               break;
-       default:
-               break;
-       }
-
-       if (sendmsg(sock, &msg, 0) < 0) {
-               char in6_str[INET6_ADDRSTRLEN];
-
-               syslog(LOG_ERR, "Failed to send DHCPV6 message to %s (%s)",
-                       inet_ntop(AF_INET6, (const void *)&srv.sin6_addr,
-                               in6_str, sizeof(in6_str)), strerror(errno));
-       }
+       sendmsg(sock, &msg, 0);
 }
 
 
@@ -679,7 +653,7 @@ static int dhcpv6_handle_advert(enum dhcpv6_msg orig, const int rc,
        uint16_t olen, otype;
        uint8_t *odata, pref = 0;
        struct dhcpv6_server_cand cand = {false, false, 0, 0, {0},
-                                       IN6ADDR_ANY_INIT, DHCPV6_SOL_MAX_RT, 
+                                       DHCPV6_SOL_MAX_RT,
                                        DHCPV6_INF_MAX_RT, NULL, NULL, 0, 0};
        bool have_na = false;
        int have_pd = 0;
@@ -710,8 +684,6 @@ static int dhcpv6_handle_advert(enum dhcpv6_msg orig, const int rc,
                } else if (otype == DHCPV6_OPT_PREF && olen >= 1 &&
                                cand.preference >= 0) {
                        cand.preference = pref = odata[0];
-               } else if (otype == DHCPV6_OPT_UNICAST && olen == sizeof(cand.server_addr)) {
-                       cand.server_addr = *(struct in6_addr *)odata;
                } else if (otype == DHCPV6_OPT_RECONF_ACCEPT) {
                        cand.wants_reconfigure = true;
                } else if (otype == DHCPV6_OPT_SOL_MAX_RT && olen == 4) {
@@ -881,8 +853,6 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
                                continue;
 
                        dhcpv6_parse_ia(ia_hdr, odata + olen + sizeof(*ia_hdr));
-               } else if (otype == DHCPV6_OPT_UNICAST && olen == sizeof(server_addr)) {
-                       server_addr = *(struct in6_addr *)odata;
                } else if (otype == DHCPV6_OPT_STATUS && olen >= 2) {
                        uint8_t *mdata = (olen > 2) ? &odata[2] : NULL;
                        uint16_t mlen = (olen > 2) ? olen - 2 : 0;
@@ -1182,18 +1152,7 @@ static void dhcpv6_handle_status_code(const enum dhcpv6_msg orig,
                break;
 
        case DHCPV6_UseMulticast:
-               switch(orig) {
-               case DHCPV6_MSG_REQUEST:
-               case DHCPV6_MSG_RENEW:
-               case DHCPV6_MSG_RELEASE:
-               case DHCPV6_MSG_DECLINE:
-                       // Message needs to be retransmitted according to RFC3315 chapter 18.1.8
-                       server_addr = in6addr_any;
-                       *ret = 0;
-                       break;
-               default:
-                       break;
-               }
+               // TODO handle multicast status code
                break;
 
        case DHCPV6_NoAddrsAvail:
index de452c04a7fef0de9488aef00fdafcac1119e779..0282500b20a4e623b78937080e28bbe2e14f59f4 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <time.h>
 #include <errno.h>
-#include <ctype.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <syslog.h>
 #include <signal.h>
 #include <string.h>
-#include <strings.h>
 #include <stdbool.h>
 
 #include <net/if.h>
 #include <sys/wait.h>
 #include <sys/syscall.h>
 #include <arpa/inet.h>
-#include <linux/if_addr.h>
 
 #include "odhcp6c.h"
 #include "ra.h"
 #include "bfd.h"
 #endif
 
-#ifndef IN6_IS_ADDR_UNIQUELOCAL
-#define IN6_IS_ADDR_UNIQUELOCAL(a) \
-       ((((__const uint32_t *) (a))[0] & htonl (0xfe000000)) \
-        == htonl (0xfc000000))
-#endif
 
 static void sighandler(int signal);
 static int usage(void);
@@ -55,7 +47,7 @@ static volatile int do_signal = 0;
 static int urandom_fd = -1, allow_slaac_only = 0;
 static bool bound = false, release = true;
 static time_t last_update = 0;
-static char *ifname = NULL;
+
 
 int main(_unused int argc, char* const argv[])
 {
@@ -179,7 +171,7 @@ int main(_unused int argc, char* const argv[])
        }
 
        openlog("odhcp6c", logopt, LOG_DAEMON);
-       ifname = argv[optind];
+       const char *ifname = argv[optind];
 
        if (help || !ifname)
                return usage();
@@ -613,64 +605,11 @@ void odhcp6c_random(void *buf, size_t len)
        read(urandom_fd, buf, len);
 }
 
-
 bool odhcp6c_is_bound(void)
 {
        return bound;
 }
 
-
-bool odhcp6c_addr_in_scope(const struct in6_addr *addr)
-{
-       FILE *fd = fopen("/proc/net/if_inet6", "r");
-       int len;
-       char buf[256];
-
-       if (fd == NULL)
-               return false;
-
-       while (fgets(buf, sizeof(buf), fd)) {
-               struct in6_addr inet6_addr;
-               uint32_t flags, dummy;
-               unsigned int i;
-               char name[8], addr_buf[32];
-
-               len = strlen(buf);
-
-               if ((len <= 0) || buf[len - 1] != '\n')
-                       return false;
-
-               buf[--len] = '\0';
-
-               if (sscanf(buf, "%s %x %x %x %x %s",
-                               addr_buf, &dummy, &dummy, &dummy, &flags, name) != 6)
-                       return false;
-
-               if (strcmp(name, ifname) ||
-                       (flags & (IFA_F_DADFAILED | IFA_F_TENTATIVE | IFA_F_DEPRECATED)))
-                       continue;
-
-               for (i = 0; i < sizeof(addr_buf); i++) {
-                       if (!isxdigit(addr_buf[i]) || isupper(addr_buf[i]))
-                               return false;
-               }
-
-               memset(&inet6_addr, 0, sizeof(inet6_addr));
-               for (i = 0; i < (sizeof(addr_buf) / 2); i++) {
-                       unsigned char byte;
-                       static const char hex[] = "0123456789abcdef";
-                       byte = ((index(hex, addr_buf[i * 2]) - hex) << 4) |
-                               (index(hex, addr_buf[i * 2 + 1]) - hex);
-                       inet6_addr.s6_addr[i] = byte;
-               }
-
-               if ((IN6_IS_ADDR_LINKLOCAL(&inet6_addr) == IN6_IS_ADDR_LINKLOCAL(addr)) &&
-                       (IN6_IS_ADDR_UNIQUELOCAL(&inet6_addr) == IN6_IS_ADDR_UNIQUELOCAL(addr)))
-                       return true;
-       }
-       return false;
-}
-
 static void sighandler(int signal)
 {
        if (signal == SIGCHLD)
index a33a92ea2b56be8bba85a4dc79eb581238c154e5..85ebf2f11815b25fe08414184bcc085e41fb0f0a 100644 (file)
@@ -41,7 +41,6 @@ enum dhcvp6_opt {
        DHCPV6_OPT_ELAPSED = 8,
        DHCPV6_OPT_RELAY_MSG = 9,
        DHCPV6_OPT_AUTH = 11,
-       DHCPV6_OPT_UNICAST = 12,
        DHCPV6_OPT_STATUS = 13,
        DHCPV6_OPT_RAPID_COMMIT = 14,
        DHCPV6_OPT_RECONF_MESSAGE = 19,
@@ -174,7 +173,6 @@ struct dhcpv6_server_cand {
        int16_t preference;
        uint8_t duid_len;
        uint8_t duid[130];
-       struct in6_addr server_addr;
        uint32_t sol_max_rt;
        uint32_t inf_max_rt;
        void *ia_na;
@@ -258,7 +256,6 @@ bool odhcp6c_signal_process(void);
 uint64_t odhcp6c_get_milli_time(void);
 void odhcp6c_random(void *buf, size_t len);
 bool odhcp6c_is_bound(void);
-bool odhcp6c_addr_in_scope(const struct in6_addr *addr);
 
 // State manipulation
 void odhcp6c_clear_state(enum odhcp6c_state state);