From ac6fc184fa544f73c0e61bb4261bc7aa8b4438bb Mon Sep 17 00:00:00 2001 From: Reuben Date: Sun, 5 Jan 2014 05:49:50 -0600 Subject: [PATCH] reindented the code ... with indent -linux -l180 *.c *.h --- defaults.h | 72 ++++++----- device-bsd44.c | 90 +++++--------- device-common.c | 78 +++++------- device-linux.c | 123 +++++++------------ includes.h | 48 ++++---- interface.c | 148 ++++++++-------------- log.c | 163 ++++++++++++------------- log.h | 3 +- netlink.c | 16 ++- netlink.h | 1 - pathnames.h | 2 +- privsep-linux.c | 27 ++--- process.c | 317 +++++++++++++++++------------------------------- radvd.c | 287 +++++++++++++++++-------------------------- radvd.h | 229 +++++++++++++++++----------------- radvdump.c | 248 +++++++++++++++---------------------- recv.c | 80 +++++------- send.c | 269 +++++++++++++++++----------------------- socket.c | 34 ++---- timer.c | 24 ++-- util.c | 35 +++--- 21 files changed, 922 insertions(+), 1372 deletions(-) diff --git a/defaults.h b/defaults.h index 3b768598..1b36ab8f 100644 --- a/defaults.h +++ b/defaults.h @@ -25,7 +25,6 @@ #define MAX2(X,Y) ( (( X ) >= ( Y )) ? ( X ) : ( Y )) - /* Router Configuration Variables: */ /* For each multicast interface: */ @@ -51,9 +50,9 @@ /* Each prefix has an associated: */ -#define DFLT_AdvValidLifetime 86400 /* seconds */ +#define DFLT_AdvValidLifetime 86400 /* seconds */ #define DFLT_AdvOnLinkFlag 1 -#define DFLT_AdvPreferredLifetime 14400 /* seconds */ +#define DFLT_AdvPreferredLifetime 14400 /* seconds */ #define DFLT_AdvAutonomousFlag 1 #define DFLT_DeprecatePrefixFlag 0 #define DFLT_DecrementLifetimesFlag 0 @@ -61,7 +60,7 @@ /* Each route has an associated: */ #define DFLT_AdvRouteLifetime(iface) (3 * (iface)->MaxRtrAdvInterval) -#define DFLT_AdvRoutePreference 0 /* medium*/ +#define DFLT_AdvRoutePreference 0 /* medium */ #define DFLT_RemoveRouteFlag 1 /* RDNSS */ @@ -81,7 +80,7 @@ #define MAX_FINAL_RTR_ADVERTISEMENTS 3 #define MIN_DELAY_BETWEEN_RAS 3.0 #define MIN_DELAY_BETWEEN_RAS_MIPv6 (30.0/1000.0) -#define MAX_RA_DELAY_TIME (1000.0/2.0) /* milliseconds */ +#define MAX_RA_DELAY_TIME (1000.0/2.0) /* milliseconds */ /* Host constants: */ @@ -95,8 +94,8 @@ #define MAX_UNICAST_SOLICIT 3 #define MAX_ANYCAST_DELAY_TIME 1 #define MAX_NEIGHBOR_ADVERTISEMENT 3 -#define REACHABLE_TIME 30000 /* milliseconds */ -#define RETRANS_TIMER 1000 /* milliseconds */ +#define REACHABLE_TIME 30000 /* milliseconds */ +#define RETRANS_TIMER 1000 /* milliseconds */ #define DELAY_FIRST_PROBE_TIME 5 #define MIN_RANDOM_FACTOR (1.0/2.0) #define MAX_RANDOM_FACTOR (3.0/2.0) @@ -116,7 +115,7 @@ #define MAX_AdvLinkMTU 131072 #define MIN_AdvReachableTime 100 -#define MAX_AdvReachableTime 3600000 /* 1 hour in milliseconds */ +#define MAX_AdvReachableTime 3600000 /* 1 hour in milliseconds */ #define MIN_AdvRetransTimer 10 #define MAX_AdvRetransTimer 3600000 @@ -153,33 +152,31 @@ #define ND_OPT_ROUTE_INFORMATION 24 /* XXX: some libc's like KAME already had nd_opt_route_info! */ -struct nd_opt_route_info_local /* route information */ - { - uint8_t nd_opt_ri_type; - uint8_t nd_opt_ri_len; - uint8_t nd_opt_ri_prefix_len; - uint8_t nd_opt_ri_flags_reserved; - uint32_t nd_opt_ri_lifetime; - struct in6_addr nd_opt_ri_prefix; - }; +struct nd_opt_route_info_local { /* route information */ + uint8_t nd_opt_ri_type; + uint8_t nd_opt_ri_len; + uint8_t nd_opt_ri_prefix_len; + uint8_t nd_opt_ri_flags_reserved; + uint32_t nd_opt_ri_lifetime; + struct in6_addr nd_opt_ri_prefix; +}; /* the reserved field is 8 bits and we're interested of the middle two: 000xx000 */ #define ND_OPT_RI_PRF_SHIFT 3 -#define ND_OPT_RI_PRF_MASK (3 << ND_OPT_RI_PRF_SHIFT) /* 00011000 = 0x18 */ +#define ND_OPT_RI_PRF_MASK (3 << ND_OPT_RI_PRF_SHIFT) /* 00011000 = 0x18 */ #undef ND_OPT_RDNSS_INFORMATION #define ND_OPT_RDNSS_INFORMATION 25 /* */ -struct nd_opt_rdnss_info_local -{ - uint8_t nd_opt_rdnssi_type; - uint8_t nd_opt_rdnssi_len; - uint16_t nd_opt_rdnssi_pref_flag_reserved; - uint32_t nd_opt_rdnssi_lifetime; - struct in6_addr nd_opt_rdnssi_addr1; - struct in6_addr nd_opt_rdnssi_addr2; - struct in6_addr nd_opt_rdnssi_addr3; +struct nd_opt_rdnss_info_local { + uint8_t nd_opt_rdnssi_type; + uint8_t nd_opt_rdnssi_len; + uint16_t nd_opt_rdnssi_pref_flag_reserved; + uint32_t nd_opt_rdnssi_lifetime; + struct in6_addr nd_opt_rdnssi_addr1; + struct in6_addr nd_opt_rdnssi_addr2; + struct in6_addr nd_opt_rdnssi_addr3; }; /* pref/flag/reserved field : yyyyx00000000000 (big endian) - 00000000yyyyx000 (little indian); where yyyy = pref, x = flag */ #if BYTE_ORDER == BIG_ENDIAN @@ -193,13 +190,12 @@ struct nd_opt_rdnss_info_local #define ND_OPT_DNSSL_INFORMATION 31 /* */ -struct nd_opt_dnssl_info_local -{ - uint8_t nd_opt_dnssli_type; - uint8_t nd_opt_dnssli_len; - uint16_t nd_opt_dnssli_reserved; - uint32_t nd_opt_dnssli_lifetime; - unsigned char nd_opt_dnssli_suffixes[]; +struct nd_opt_dnssl_info_local { + uint8_t nd_opt_dnssli_type; + uint8_t nd_opt_dnssli_len; + uint16_t nd_opt_dnssli_reserved; + uint32_t nd_opt_dnssli_lifetime; + unsigned char nd_opt_dnssli_suffixes[]; }; /* Flags */ @@ -227,13 +223,13 @@ struct nd_opt_dnssl_info_local #define MIN_MinRtrAdvInterval_MIPv6 (3.0/100.0) #define MIN_MaxRtrAdvInterval_MIPv6 (7.0/100.0) -#define RTR_SOLICITATION_INTERVAL_MIPv6 1 /* Recommended value by MIPv6 */ +#define RTR_SOLICITATION_INTERVAL_MIPv6 1 /* Recommended value by MIPv6 */ #define Cautious_MaxRtrAdvInterval (2.0/10.0) #define Cautious_MaxRtrAdvInterval_Leeway (2.0/100.0) -#define MIN_HomeAgentLifetime 1 /* 0 must NOT be used */ -#define MAX_HomeAgentLifetime 65520 /* 18.2 hours in secs */ +#define MIN_HomeAgentLifetime 1 /* 0 must NOT be used */ +#define MAX_HomeAgentLifetime 65520 /* 18.2 hours in secs */ /* #define MAX_RTR_SOLICITATIONS This MAY be ignored by MIPv6 */ @@ -245,7 +241,7 @@ struct nd_opt_dnssl_info_local #ifndef ND_OPT_HAI_FLAG_SUPPORT_MR #if BYTE_ORDER == BIG_ENDIAN #define ND_OPT_HAI_FLAG_SUPPORT_MR 0x8000 -#else /* BYTE_ORDER == LITTLE_ENDIAN */ +#else /* BYTE_ORDER == LITTLE_ENDIAN */ #define ND_OPT_HAI_FLAG_SUPPORT_MR 0x0080 #endif #endif diff --git a/device-bsd44.c b/device-bsd44.c index 179b1345..1227c97f 100644 --- a/device-bsd44.c +++ b/device-bsd44.c @@ -25,8 +25,7 @@ static uint8_t ll_prefix[] = { 0xfe, 0x80 }; * determines the link layer token length and checks it against * the defined prefixes */ -int -update_device_info(struct Interface *iface) +int update_device_info(struct Interface *iface) { struct ifaddrs *addresses = 0, *ifa; @@ -34,14 +33,14 @@ update_device_info(struct Interface *iface) struct AdvPrefix *prefix; char zero[sizeof(iface->if_addr)]; - if(if_nametoindex(iface->Name) == 0){ + if (if_nametoindex(iface->Name) == 0) { flog(LOG_ERR, "%s not found: %s", iface->Name, strerror(errno)); goto ret; } - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ-1); - ifr.ifr_name[IFNAMSIZ-1] = '\0'; + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) { flog(LOG_ERR, "ioctl(SIOCGIFMTU) failed for %s: %s", iface->Name, strerror(errno)); @@ -51,14 +50,12 @@ update_device_info(struct Interface *iface) dlog(LOG_DEBUG, 3, "mtu for %s is %d", iface->Name, ifr.ifr_mtu); iface->if_maxmtu = ifr.ifr_mtu; - if (getifaddrs(&addresses) != 0) - { + if (getifaddrs(&addresses) != 0) { flog(LOG_ERR, "getifaddrs failed: %s(%d)", strerror(errno), errno); goto ret; } - for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next) - { + for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next) { if (strcmp(ifa->ifa_name, iface->Name) != 0) continue; @@ -68,21 +65,17 @@ update_device_info(struct Interface *iface) if (ifa->ifa_addr->sa_family != AF_LINK) continue; - struct sockaddr_dl *dl = (struct sockaddr_dl*)ifa->ifa_addr; + struct sockaddr_dl *dl = (struct sockaddr_dl *)ifa->ifa_addr; - - if (dl->sdl_alen > sizeof(iface->if_addr)) - { - flog(LOG_ERR, "address length %d too big for", - dl->sdl_alen, - iface->Name); + if (dl->sdl_alen > sizeof(iface->if_addr)) { + flog(LOG_ERR, "address length %d too big for", dl->sdl_alen, iface->Name); goto ret; } memcpy(iface->if_hwaddr, LLADDR(dl), dl->sdl_alen); iface->if_hwaddr_len = dl->sdl_alen << 3; - switch(dl->sdl_type) { + switch (dl->sdl_type) { case IFT_ETHER: case IFT_ISO88023: iface->if_prefix_len = 64; @@ -96,27 +89,20 @@ update_device_info(struct Interface *iface) break; } - dlog(LOG_DEBUG, 3, "link layer token length for %s is %d", iface->Name, - iface->if_hwaddr_len); + dlog(LOG_DEBUG, 3, "link layer token length for %s is %d", iface->Name, iface->if_hwaddr_len); - dlog(LOG_DEBUG, 3, "prefix length for %s is %d", iface->Name, - iface->if_prefix_len); + dlog(LOG_DEBUG, 3, "prefix length for %s is %d", iface->Name, iface->if_prefix_len); if (iface->if_prefix_len != -1) { memset(zero, 0, dl->sdl_alen); if (!memcmp(iface->if_hwaddr, zero, dl->sdl_alen)) - flog(LOG_WARNING, "WARNING, MAC address on %s is all zero!", - iface->Name); + flog(LOG_WARNING, "WARNING, MAC address on %s is all zero!", iface->Name); } prefix = iface->AdvPrefixList; - while (prefix) - { - if ((iface->if_prefix_len != -1) && - (iface->if_prefix_len != prefix->PrefixLen)) - { - flog(LOG_WARNING, "prefix length should be %d for %s", - iface->if_prefix_len, iface->Name); + while (prefix) { + if ((iface->if_prefix_len != -1) && (iface->if_prefix_len != prefix->PrefixLen)) { + flog(LOG_WARNING, "prefix length should be %d for %s", iface->if_prefix_len, iface->Name); } prefix = prefix->next; @@ -126,8 +112,7 @@ update_device_info(struct Interface *iface) return 0; } - -ret: + ret: iface->if_maxmtu = -1; iface->if_hwaddr_len = -1; iface->if_prefix_len = -1; @@ -144,14 +129,12 @@ int setup_linklocal_addr(struct Interface *iface) { struct ifaddrs *addresses = 0, *ifa; - if (getifaddrs(&addresses) != 0) - { + if (getifaddrs(&addresses) != 0) { flog(LOG_ERR, "getifaddrs failed: %s(%d)", strerror(errno), errno); goto ret; } - for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next) - { + for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next) { if (strcmp(ifa->ifa_name, iface->Name) != 0) continue; @@ -159,7 +142,7 @@ int setup_linklocal_addr(struct Interface *iface) continue; if (ifa->ifa_addr->sa_family == AF_LINK) { - struct sockaddr_dl *dl = (struct sockaddr_dl*)ifa->ifa_addr; + struct sockaddr_dl *dl = (struct sockaddr_dl *)ifa->ifa_addr; if (memcmp(iface->Name, dl->sdl_data, dl->sdl_nlen) == 0) iface->if_index = dl->sdl_index; continue; @@ -168,7 +151,7 @@ int setup_linklocal_addr(struct Interface *iface) if (ifa->ifa_addr->sa_family != AF_INET6) continue; - struct sockaddr_in6 *a6 = (struct sockaddr_in6*)ifa->ifa_addr; + struct sockaddr_in6 *a6 = (struct sockaddr_in6 *)ifa->ifa_addr; /* Skip if it is not a linklocal address */ if (memcmp(&(a6->sin6_addr), ll_prefix, sizeof(ll_prefix)) != 0) @@ -179,8 +162,8 @@ int setup_linklocal_addr(struct Interface *iface) return 0; } -ret: - if(addresses) + ret: + if (addresses) freeifaddrs(addresses); flog(LOG_ERR, "no linklocal address configured for %s", iface->Name); return -1; @@ -196,35 +179,26 @@ int check_allrouters_membership(struct Interface *iface) return (0); } -int -set_interface_linkmtu(const char *iface, uint32_t mtu) +int set_interface_linkmtu(const char *iface, uint32_t mtu) { - dlog(LOG_DEBUG, 4, "setting LinkMTU (%u) for %s is not supported", - mtu, iface); + dlog(LOG_DEBUG, 4, "setting LinkMTU (%u) for %s is not supported", mtu, iface); return -1; } -int -set_interface_curhlim(const char *iface, uint8_t hlim) +int set_interface_curhlim(const char *iface, uint8_t hlim) { - dlog(LOG_DEBUG, 4, "setting CurHopLimit (%u) for %s is not supported", - hlim, iface); + dlog(LOG_DEBUG, 4, "setting CurHopLimit (%u) for %s is not supported", hlim, iface); return -1; } -int -set_interface_reachtime(const char *iface, uint32_t rtime) +int set_interface_reachtime(const char *iface, uint32_t rtime) { - dlog(LOG_DEBUG, 4, "setting BaseReachableTime (%u) for %s is not supported", - rtime, iface); + dlog(LOG_DEBUG, 4, "setting BaseReachableTime (%u) for %s is not supported", rtime, iface); return -1; } -int -set_interface_retranstimer(const char *iface, uint32_t rettimer) +int set_interface_retranstimer(const char *iface, uint32_t rettimer) { - dlog(LOG_DEBUG, 4, "setting RetransTimer (%u) for %s is not supported", - rettimer, iface); + dlog(LOG_DEBUG, 4, "setting RetransTimer (%u) for %s is not supported", rettimer, iface); return -1; } - diff --git a/device-common.c b/device-common.c index 6b5c38b2..25cc8711 100644 --- a/device-common.c +++ b/device-common.c @@ -17,38 +17,32 @@ #include "radvd.h" #include "defaults.h" -int -check_device(struct Interface *iface) +int check_device(struct Interface *iface) { - struct ifreq ifr; + struct ifreq ifr; - strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ-1); - ifr.ifr_name[IFNAMSIZ-1] = '\0'; + strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; - if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) - { + if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { if (!iface->IgnoreIfMissing) - flog(LOG_ERR, "ioctl(SIOCGIFFLAGS) failed for %s: %s", - iface->Name, strerror(errno)); + flog(LOG_ERR, "ioctl(SIOCGIFFLAGS) failed for %s: %s", iface->Name, strerror(errno)); return (-1); } - if (!(ifr.ifr_flags & IFF_UP)) - { + if (!(ifr.ifr_flags & IFF_UP)) { if (!iface->IgnoreIfMissing) - flog(LOG_ERR, "interface %s is not UP", iface->Name); + flog(LOG_ERR, "interface %s is not UP", iface->Name); return (-1); } - if (!(ifr.ifr_flags & IFF_RUNNING)) - { + if (!(ifr.ifr_flags & IFF_RUNNING)) { if (!iface->IgnoreIfMissing) - flog(LOG_ERR, "interface %s is not RUNNING", iface->Name); + flog(LOG_ERR, "interface %s is not RUNNING", iface->Name); return (-1); } - if (!iface->UnicastOnly && !(ifr.ifr_flags & IFF_MULTICAST)) - { + if (!iface->UnicastOnly && !(ifr.ifr_flags & IFF_MULTICAST)) { flog(LOG_INFO, "interface %s does not support multicast, forcing UnicastOnly", iface->Name); iface->UnicastOnly = 1; } @@ -56,41 +50,35 @@ check_device(struct Interface *iface) return 0; } -int -get_v4addr(const char *ifn, unsigned int *dst) +int get_v4addr(const char *ifn, unsigned int *dst) { - struct ifreq ifr; - struct sockaddr_in *addr; - int fd; + struct ifreq ifr; + struct sockaddr_in *addr; + int fd; - if( ( fd = socket(AF_INET,SOCK_DGRAM,0) ) < 0 ) - { - flog(LOG_ERR, "create socket for IPv4 ioctl failed for %s: %s", - ifn, strerror(errno)); - return (-1); - } + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + flog(LOG_ERR, "create socket for IPv4 ioctl failed for %s: %s", ifn, strerror(errno)); + return (-1); + } - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ifn, IFNAMSIZ-1); - ifr.ifr_name[IFNAMSIZ-1] = '\0'; - ifr.ifr_addr.sa_family = AF_INET; + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, ifn, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; + ifr.ifr_addr.sa_family = AF_INET; - if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) - { - flog(LOG_ERR, "ioctl(SIOCGIFADDR) failed for %s: %s", - ifn, strerror(errno)); - close( fd ); - return (-1); - } + if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) { + flog(LOG_ERR, "ioctl(SIOCGIFADDR) failed for %s: %s", ifn, strerror(errno)); + close(fd); + return (-1); + } - addr = (struct sockaddr_in *)(&ifr.ifr_addr); + addr = (struct sockaddr_in *)(&ifr.ifr_addr); - dlog(LOG_DEBUG, 3, "IPv4 address for %s is %s", ifn, - inet_ntoa( addr->sin_addr ) ); + dlog(LOG_DEBUG, 3, "IPv4 address for %s is %s", ifn, inet_ntoa(addr->sin_addr)); - *dst = addr->sin_addr.s_addr; + *dst = addr->sin_addr.s_addr; - close( fd ); + close(fd); - return 0; + return 0; } diff --git a/device-linux.c b/device-linux.c index f42533bd..bbf508d7 100644 --- a/device-linux.c +++ b/device-linux.c @@ -27,19 +27,17 @@ * determines the link layer token length and checks it against * the defined prefixes */ -int -update_device_info(struct Interface *iface) +int update_device_info(struct Interface *iface) { - struct ifreq ifr; + struct ifreq ifr; struct AdvPrefix *prefix; char zero[sizeof(iface->if_addr)]; - strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ-1); - ifr.ifr_name[IFNAMSIZ-1] = '\0'; + strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) { - flog(LOG_ERR, "ioctl(SIOCGIFMTU) failed for %s: %s", - iface->Name, strerror(errno)); + flog(LOG_ERR, "ioctl(SIOCGIFMTU) failed for %s: %s", iface->Name, strerror(errno)); return (-1); } @@ -47,12 +45,10 @@ update_device_info(struct Interface *iface) iface->if_maxmtu = ifr.ifr_mtu; if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { - flog(LOG_ERR, "ioctl(SIOCGIFHWADDR) failed for %s: %s", - iface->Name, strerror(errno)); + flog(LOG_ERR, "ioctl(SIOCGIFHWADDR) failed for %s: %s", iface->Name, strerror(errno)); return (-1); } - switch(ifr.ifr_hwaddr.sa_family) - { + switch (ifr.ifr_hwaddr.sa_family) { case ARPHRD_ETHER: iface->if_hwaddr_len = 48; iface->if_prefix_len = 64; @@ -64,7 +60,7 @@ update_device_info(struct Interface *iface) iface->if_prefix_len = 64; dlog(LOG_DEBUG, 3, "hardware type for %s is ARPHRD_FDDI", iface->Name); break; -#endif /* ARPHDR_FDDI */ +#endif /* ARPHDR_FDDI */ #ifdef ARPHRD_ARCNET case ARPHRD_ARCNET: iface->if_hwaddr_len = 8; @@ -72,48 +68,40 @@ update_device_info(struct Interface *iface) iface->if_maxmtu = -1; dlog(LOG_DEBUG, 3, "hardware type for %s is ARPHRD_ARCNET", iface->Name); break; -#endif /* ARPHDR_ARCNET */ +#endif /* ARPHDR_ARCNET */ default: iface->if_hwaddr_len = -1; iface->if_prefix_len = -1; iface->if_maxmtu = -1; - dlog(LOG_DEBUG, 3, "hardware type for %s is %d", iface->Name, - ifr.ifr_hwaddr.sa_family); + dlog(LOG_DEBUG, 3, "hardware type for %s is %d", iface->Name, ifr.ifr_hwaddr.sa_family); break; } - dlog(LOG_DEBUG, 3, "link layer token length for %s is %d", iface->Name, - iface->if_hwaddr_len); + dlog(LOG_DEBUG, 3, "link layer token length for %s is %d", iface->Name, iface->if_hwaddr_len); - dlog(LOG_DEBUG, 3, "prefix length for %s is %d", iface->Name, - iface->if_prefix_len); + dlog(LOG_DEBUG, 3, "prefix length for %s is %d", iface->Name, iface->if_prefix_len); if (iface->if_hwaddr_len != -1) { unsigned int if_hwaddr_len_bytes = (iface->if_hwaddr_len + 7) >> 3; if (if_hwaddr_len_bytes > sizeof(iface->if_hwaddr)) { flog(LOG_ERR, "address length %d too big for %s", if_hwaddr_len_bytes, iface->Name); - return(-2); + return (-2); } memcpy(iface->if_hwaddr, ifr.ifr_hwaddr.sa_data, if_hwaddr_len_bytes); memset(zero, 0, sizeof(zero)); if (!memcmp(iface->if_hwaddr, zero, if_hwaddr_len_bytes)) - flog(LOG_WARNING, "WARNING, MAC address on %s is all zero!", - iface->Name); + flog(LOG_WARNING, "WARNING, MAC address on %s is all zero!", iface->Name); } prefix = iface->AdvPrefixList; - while (prefix) - { - if ((iface->if_prefix_len != -1) && - (iface->if_prefix_len != prefix->PrefixLen)) - { - flog(LOG_WARNING, "prefix length should be %d for %s", - iface->if_prefix_len, iface->Name); - } - - prefix = prefix->next; + while (prefix) { + if ((iface->if_prefix_len != -1) && (iface->if_prefix_len != prefix->PrefixLen)) { + flog(LOG_WARNING, "prefix length should be %d for %s", iface->if_prefix_len, iface->Name); + } + + prefix = prefix->next; } return (0); @@ -130,26 +118,18 @@ int setup_linklocal_addr(struct Interface *iface) unsigned int plen, scope, dad_status, if_idx; char devname[IFNAMSIZ]; - if ((fp = fopen(PATH_PROC_NET_IF_INET6, "r")) == NULL) - { - flog(LOG_ERR, "can't open %s: %s", PATH_PROC_NET_IF_INET6, - strerror(errno)); + if ((fp = fopen(PATH_PROC_NET_IF_INET6, "r")) == NULL) { + flog(LOG_ERR, "can't open %s: %s", PATH_PROC_NET_IF_INET6, strerror(errno)); return (-1); } - while (fscanf(fp, "%32s %x %02x %02x %02x %15s\n", - str_addr, &if_idx, &plen, &scope, &dad_status, - devname) != EOF) - { - if (scope == IPV6_ADDR_LINKLOCAL && - strcmp(devname, iface->Name) == 0) - { + while (fscanf(fp, "%32s %x %02x %02x %02x %15s\n", str_addr, &if_idx, &plen, &scope, &dad_status, devname) != EOF) { + if (scope == IPV6_ADDR_LINKLOCAL && strcmp(devname, iface->Name) == 0) { struct in6_addr addr; unsigned int ap; int i; - for (i=0; i<16; i++) - { + for (i = 0; i < 16; i++) { sscanf(str_addr + i * 2, "%02x", &ap); addr.s6_addr[i] = (unsigned char)ap; } @@ -177,11 +157,9 @@ int setup_allrouters_membership(struct Interface *iface) mreq.ipv6mr_multiaddr.s6_addr32[0] = htonl(0xFF020000); mreq.ipv6mr_multiaddr.s6_addr32[3] = htonl(0x2); - if (setsockopt(sock, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) - { + if (setsockopt(sock, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { /* linux-2.6.12-bk4 returns error with HUP signal but keep listening */ - if (errno != EADDRINUSE) - { + if (errno != EADDRINUSE) { flog(LOG_ERR, "can't join ipv6-allrouters on %s", iface->Name); return (-1); } @@ -192,27 +170,25 @@ int setup_allrouters_membership(struct Interface *iface) int check_allrouters_membership(struct Interface *iface) { - #define ALL_ROUTERS_MCAST "ff020000000000000000000000000002" +#define ALL_ROUTERS_MCAST "ff020000000000000000000000000002" FILE *fp; - unsigned int if_idx, allrouters_ok=0; - char addr[32+1]; - char buffer[301] = {""}, *str; - int ret=0; - - if ((fp = fopen(PATH_PROC_NET_IGMP6, "r")) == NULL) - { - flog(LOG_ERR, "can't open %s: %s", PATH_PROC_NET_IGMP6, - strerror(errno)); + unsigned int if_idx, allrouters_ok = 0; + char addr[32 + 1]; + char buffer[301] = { "" }, *str; + int ret = 0; + + if ((fp = fopen(PATH_PROC_NET_IGMP6, "r")) == NULL) { + flog(LOG_ERR, "can't open %s: %s", PATH_PROC_NET_IGMP6, strerror(errno)); return (-1); } str = fgets(buffer, 300, fp); - while (str && (ret = sscanf(str, "%u %*s %32[0-9A-Fa-f]", &if_idx, addr)) ) { + while (str && (ret = sscanf(str, "%u %*s %32[0-9A-Fa-f]", &if_idx, addr))) { if (ret == 2) { if (iface->if_index == if_idx) { - if (strncmp(addr, ALL_ROUTERS_MCAST, sizeof(addr)) == 0){ + if (strncmp(addr, ALL_ROUTERS_MCAST, sizeof(addr)) == 0) { allrouters_ok = 1; break; } @@ -228,17 +204,14 @@ int check_allrouters_membership(struct Interface *iface) return setup_allrouters_membership(iface); } - return(0); + return (0); } /* note: also called from the root context */ -int -set_interface_var(const char *iface, - const char *var, const char *name, - uint32_t val) +int set_interface_var(const char *iface, const char *var, const char *name, uint32_t val) { FILE *fp; - char spath[64+IFNAMSIZ]; /* XXX: magic constant */ + char spath[64 + IFNAMSIZ]; /* XXX: magic constant */ if (snprintf(spath, sizeof(spath), var, iface) >= sizeof(spath)) return -1; @@ -252,8 +225,7 @@ set_interface_var(const char *iface, fp = fopen(spath, "w"); if (!fp) { if (name) - flog(LOG_ERR, "failed to set %s (%u) for %s: %s", - name, val, iface, strerror(errno)); + flog(LOG_ERR, "failed to set %s (%u) for %s: %s", name, val, iface, strerror(errno)); return -1; } fprintf(fp, "%u", val); @@ -262,27 +234,22 @@ set_interface_var(const char *iface, return 0; } -int -set_interface_linkmtu(const char *iface, uint32_t mtu) +int set_interface_linkmtu(const char *iface, uint32_t mtu) { return privsep_interface_linkmtu(iface, mtu); } -int -set_interface_curhlim(const char *iface, uint8_t hlim) +int set_interface_curhlim(const char *iface, uint8_t hlim) { return privsep_interface_curhlim(iface, hlim); } -int -set_interface_reachtime(const char *iface, uint32_t rtime) +int set_interface_reachtime(const char *iface, uint32_t rtime) { return privsep_interface_reachtime(iface, rtime); } -int -set_interface_retranstimer(const char *iface, uint32_t rettimer) +int set_interface_retranstimer(const char *iface, uint32_t rettimer) { return privsep_interface_retranstimer(iface, rettimer); } - diff --git a/includes.h b/includes.h index 77659256..805efff1 100644 --- a/includes.h +++ b/includes.h @@ -32,29 +32,29 @@ #include #ifdef HAVE_INTTYPES_H -# include +#include #endif #ifdef HAVE_SYS_PARAM_H -# include +#include #else -# ifdef HAVE_MACHINE_PARAM_H -# include -# endif -# ifdef HAVE_MACHINE_LIMITS_H -# include -# endif +#ifdef HAVE_MACHINE_PARAM_H +#include +#endif +#ifdef HAVE_MACHINE_LIMITS_H +#include +#endif #endif #if TIME_WITH_SYS_TIME -# include -# include +#include +#include #else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif +#if HAVE_SYS_TIME_H +#include +#else +#include +#endif #endif #include @@ -73,31 +73,31 @@ #include #ifdef HAVE_SYS_SYSCTL_H -# include +#include #endif #include #ifdef HAVE_NET_IF_DL_H -# include +#include #endif #ifdef HAVE_NET_IF_TYPES_H -# include +#include #endif #if defined(HAVE_NET_IF_ARP_H) && !defined(ARPHRD_ETHER) -# include -#endif /* defined(HAVE_NET_IF_ARP_H) && !defined(ARPHRD_ETHER) */ +#include +#endif /* defined(HAVE_NET_IF_ARP_H) && !defined(ARPHRD_ETHER) */ #ifdef HAVE_SYS_SOCKIO_H -# include +#include #endif #ifdef HAVE_GETOPT_H -# include +#include #endif #ifdef HAVE_IFADDRS_H -# include +#include #endif -#endif /* INCLUDES_H */ +#endif /* INCLUDES_H */ diff --git a/interface.c b/interface.c index a7987903..c260cd50 100644 --- a/interface.c +++ b/interface.c @@ -17,27 +17,26 @@ #include "radvd.h" #include "defaults.h" -void -iface_init_defaults(struct Interface *iface) +void iface_init_defaults(struct Interface *iface) { memset(iface, 0, sizeof(struct Interface)); - iface->cease_adv = 0; + iface->cease_adv = 0; - iface->HasFailed = 0; - iface->IgnoreIfMissing = DFLT_IgnoreIfMissing; - iface->AdvSendAdvert = DFLT_AdvSendAdv; - iface->MaxRtrAdvInterval = DFLT_MaxRtrAdvInterval; + iface->HasFailed = 0; + iface->IgnoreIfMissing = DFLT_IgnoreIfMissing; + iface->AdvSendAdvert = DFLT_AdvSendAdv; + iface->MaxRtrAdvInterval = DFLT_MaxRtrAdvInterval; iface->AdvSourceLLAddress = DFLT_AdvSourceLLAddress; - iface->AdvReachableTime = DFLT_AdvReachableTime; - iface->AdvRetransTimer = DFLT_AdvRetransTimer; - iface->AdvLinkMTU = DFLT_AdvLinkMTU; - iface->AdvCurHopLimit = DFLT_AdvCurHopLimit; - iface->AdvIntervalOpt = DFLT_AdvIntervalOpt; - iface->AdvHomeAgentInfo = DFLT_AdvHomeAgentInfo; - iface->AdvHomeAgentFlag = DFLT_AdvHomeAgentFlag; + iface->AdvReachableTime = DFLT_AdvReachableTime; + iface->AdvRetransTimer = DFLT_AdvRetransTimer; + iface->AdvLinkMTU = DFLT_AdvLinkMTU; + iface->AdvCurHopLimit = DFLT_AdvCurHopLimit; + iface->AdvIntervalOpt = DFLT_AdvIntervalOpt; + iface->AdvHomeAgentInfo = DFLT_AdvHomeAgentInfo; + iface->AdvHomeAgentFlag = DFLT_AdvHomeAgentFlag; iface->HomeAgentPreference = DFLT_HomeAgentPreference; - iface->MinDelayBetweenRAs = DFLT_MinDelayBetweenRAs; + iface->MinDelayBetweenRAs = DFLT_MinDelayBetweenRAs; iface->AdvMobRtrSupportFlag = DFLT_AdvMobRtrSupportFlag; iface->MinRtrAdvInterval = -1; @@ -46,8 +45,7 @@ iface_init_defaults(struct Interface *iface) iface->HomeAgentLifetime = -1; } -void -prefix_init_defaults(struct AdvPrefix *prefix) +void prefix_init_defaults(struct AdvPrefix *prefix) { memset(prefix, 0, sizeof(struct AdvPrefix)); @@ -65,8 +63,7 @@ prefix_init_defaults(struct AdvPrefix *prefix) prefix->curr_preferredlft = prefix->AdvPreferredLifetime; } -void -route_init_defaults(struct AdvRoute *route, struct Interface *iface) +void route_init_defaults(struct AdvRoute *route, struct Interface *iface) { memset(route, 0, sizeof(struct AdvRoute)); @@ -75,8 +72,7 @@ route_init_defaults(struct AdvRoute *route, struct Interface *iface) route->RemoveRouteFlag = DFLT_RemoveRouteFlag; } -void -rdnss_init_defaults(struct AdvRDNSS *rdnss, struct Interface *iface) +void rdnss_init_defaults(struct AdvRDNSS *rdnss, struct Interface *iface) { memset(rdnss, 0, sizeof(struct AdvRDNSS)); @@ -85,8 +81,7 @@ rdnss_init_defaults(struct AdvRDNSS *rdnss, struct Interface *iface) rdnss->FlushRDNSSFlag = DFLT_FlushRDNSSFlag; } -void -dnssl_init_defaults(struct AdvDNSSL *dnssl, struct Interface *iface) +void dnssl_init_defaults(struct AdvDNSSL *dnssl, struct Interface *iface) { memset(dnssl, 0, sizeof(struct AdvDNSSL)); @@ -94,8 +89,7 @@ dnssl_init_defaults(struct AdvDNSSL *dnssl, struct Interface *iface) dnssl->FlushDNSSLFlag = DFLT_FlushDNSSLFlag; } -int -check_iface(struct Interface *iface) +int check_iface(struct Interface *iface) { struct AdvPrefix *prefix; struct AdvRoute *route; @@ -103,18 +97,14 @@ check_iface(struct Interface *iface) int MIPv6 = 0; /* Check if we use Mobile IPv6 extensions */ - if (iface->AdvHomeAgentFlag || iface->AdvHomeAgentInfo || - iface->AdvIntervalOpt) - { + if (iface->AdvHomeAgentFlag || iface->AdvHomeAgentInfo || iface->AdvIntervalOpt) { MIPv6 = 1; flog(LOG_INFO, "using Mobile IPv6 extensions"); } prefix = iface->AdvPrefixList; - while (!MIPv6 && prefix) - { - if (prefix->AdvRouterAddr) - { + while (!MIPv6 && prefix) { + if (prefix->AdvRouterAddr) { MIPv6 = 1; } prefix = prefix->next; @@ -123,65 +113,44 @@ check_iface(struct Interface *iface) if (iface->MinRtrAdvInterval < 0) iface->MinRtrAdvInterval = DFLT_MinRtrAdvInterval(iface); - if ((iface->MinRtrAdvInterval < (MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : MIN_MinRtrAdvInterval)) || - (iface->MinRtrAdvInterval > MAX_MinRtrAdvInterval(iface))) - { + if ((iface->MinRtrAdvInterval < (MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : MIN_MinRtrAdvInterval)) || (iface->MinRtrAdvInterval > MAX_MinRtrAdvInterval(iface))) { flog(LOG_ERR, - "MinRtrAdvInterval for %s (%.2f) must be at least %.2f but no more than 3/4 of MaxRtrAdvInterval (%.2f)", - iface->Name, iface->MinRtrAdvInterval, - MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : (int)MIN_MinRtrAdvInterval, - MAX_MinRtrAdvInterval(iface)); + "MinRtrAdvInterval for %s (%.2f) must be at least %.2f but no more than 3/4 of MaxRtrAdvInterval (%.2f)", + iface->Name, iface->MinRtrAdvInterval, MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : (int)MIN_MinRtrAdvInterval, MAX_MinRtrAdvInterval(iface)); res = -1; } if ((iface->MaxRtrAdvInterval < (MIPv6 ? MIN_MaxRtrAdvInterval_MIPv6 : MIN_MaxRtrAdvInterval)) - || (iface->MaxRtrAdvInterval > MAX_MaxRtrAdvInterval)) - { + || (iface->MaxRtrAdvInterval > MAX_MaxRtrAdvInterval)) { flog(LOG_ERR, - "MaxRtrAdvInterval for %s (%.2f) must be between %.2f and %d", - iface->Name, iface->MaxRtrAdvInterval, - MIPv6 ? MIN_MaxRtrAdvInterval_MIPv6 : (int)MIN_MaxRtrAdvInterval, - MAX_MaxRtrAdvInterval); + "MaxRtrAdvInterval for %s (%.2f) must be between %.2f and %d", + iface->Name, iface->MaxRtrAdvInterval, MIPv6 ? MIN_MaxRtrAdvInterval_MIPv6 : (int)MIN_MaxRtrAdvInterval, MAX_MaxRtrAdvInterval); res = -1; } - if (iface->MinDelayBetweenRAs < (MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS)) - { + if (iface->MinDelayBetweenRAs < (MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS)) { flog(LOG_ERR, - "MinDelayBetweenRAs for %s (%.2f) must be at least %.2f", - iface->Name, iface->MinDelayBetweenRAs, - MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS); + "MinDelayBetweenRAs for %s (%.2f) must be at least %.2f", iface->Name, iface->MinDelayBetweenRAs, MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS); res = -1; } - if ((iface->AdvLinkMTU != 0) && - ((iface->AdvLinkMTU < MIN_AdvLinkMTU) || - (iface->if_maxmtu != -1 && (iface->AdvLinkMTU > iface->if_maxmtu)))) - { - flog(LOG_ERR, "AdvLinkMTU for %s (%u) must be zero or between %u and %u", - iface->Name, iface->AdvLinkMTU, MIN_AdvLinkMTU, iface->if_maxmtu); + if ((iface->AdvLinkMTU != 0) && ((iface->AdvLinkMTU < MIN_AdvLinkMTU) || (iface->if_maxmtu != -1 && (iface->AdvLinkMTU > iface->if_maxmtu)))) { + flog(LOG_ERR, "AdvLinkMTU for %s (%u) must be zero or between %u and %u", iface->Name, iface->AdvLinkMTU, MIN_AdvLinkMTU, iface->if_maxmtu); res = -1; } - if (iface->AdvReachableTime > MAX_AdvReachableTime) - { - flog(LOG_ERR, - "AdvReachableTime for %s (%u) must not be greater than %u", - iface->Name, iface->AdvReachableTime, MAX_AdvReachableTime); + if (iface->AdvReachableTime > MAX_AdvReachableTime) { + flog(LOG_ERR, "AdvReachableTime for %s (%u) must not be greater than %u", iface->Name, iface->AdvReachableTime, MAX_AdvReachableTime); res = -1; } if (iface->AdvDefaultLifetime < 0) iface->AdvDefaultLifetime = DFLT_AdvDefaultLifetime(iface); - if ((iface->AdvDefaultLifetime != 0) && - ((iface->AdvDefaultLifetime > MAX_AdvDefaultLifetime) || - (iface->AdvDefaultLifetime < MIN_AdvDefaultLifetime(iface)))) - { + if ((iface->AdvDefaultLifetime != 0) && ((iface->AdvDefaultLifetime > MAX_AdvDefaultLifetime) || (iface->AdvDefaultLifetime < MIN_AdvDefaultLifetime(iface)))) { flog(LOG_ERR, - "AdvDefaultLifetime for %s (%u) must be zero or between %u and %u", - iface->Name, iface->AdvDefaultLifetime, (int)MIN_AdvDefaultLifetime(iface), - MAX_AdvDefaultLifetime); + "AdvDefaultLifetime for %s (%u) must be zero or between %u and %u", + iface->Name, iface->AdvDefaultLifetime, (int)MIN_AdvDefaultLifetime(iface), MAX_AdvDefaultLifetime); res = -1; } @@ -190,61 +159,44 @@ check_iface(struct Interface *iface) iface->HomeAgentLifetime = DFLT_HomeAgentLifetime(iface); /* Mobile IPv6 ext */ - if (iface->AdvHomeAgentInfo) - { - if ((iface->HomeAgentLifetime > MAX_HomeAgentLifetime) || - (iface->HomeAgentLifetime < MIN_HomeAgentLifetime)) - { + if (iface->AdvHomeAgentInfo) { + if ((iface->HomeAgentLifetime > MAX_HomeAgentLifetime) || (iface->HomeAgentLifetime < MIN_HomeAgentLifetime)) { flog(LOG_ERR, - "HomeAgentLifetime for %s (%u) must be between %u and %u", - iface->Name, iface->HomeAgentLifetime, - MIN_HomeAgentLifetime, MAX_HomeAgentLifetime); + "HomeAgentLifetime for %s (%u) must be between %u and %u", iface->Name, iface->HomeAgentLifetime, MIN_HomeAgentLifetime, MAX_HomeAgentLifetime); res = -1; } } /* Mobile IPv6 ext */ - if (iface->AdvHomeAgentInfo && !(iface->AdvHomeAgentFlag)) - { - flog(LOG_ERR, - "AdvHomeAgentFlag for %s must be set with HomeAgentInfo", iface->Name); + if (iface->AdvHomeAgentInfo && !(iface->AdvHomeAgentFlag)) { + flog(LOG_ERR, "AdvHomeAgentFlag for %s must be set with HomeAgentInfo", iface->Name); res = -1; } - if (iface->AdvMobRtrSupportFlag && !(iface->AdvHomeAgentInfo)) - { - flog(LOG_ERR, - "AdvHomeAgentInfo for %s must be set with AdvMobRtrSupportFlag", iface->Name); + if (iface->AdvMobRtrSupportFlag && !(iface->AdvHomeAgentInfo)) { + flog(LOG_ERR, "AdvHomeAgentInfo for %s must be set with AdvMobRtrSupportFlag", iface->Name); res = -1; } /* XXX: need this? prefix = iface->AdvPrefixList; */ - while (prefix) - { - if (prefix->PrefixLen > MAX_PrefixLen) - { + while (prefix) { + if (prefix->PrefixLen > MAX_PrefixLen) { flog(LOG_ERR, "invalid prefix length (%u) for %s", prefix->PrefixLen, iface->Name); res = -1; } - if (prefix->AdvPreferredLifetime > prefix->AdvValidLifetime) - { - flog(LOG_ERR, "AdvValidLifetime for %s (%u) must be " - "greater than AdvPreferredLifetime for", - iface->Name, prefix->AdvValidLifetime); + if (prefix->AdvPreferredLifetime > prefix->AdvValidLifetime) { + flog(LOG_ERR, "AdvValidLifetime for %s (%u) must be " "greater than AdvPreferredLifetime for", iface->Name, prefix->AdvValidLifetime); res = -1; } prefix = prefix->next; } - route = iface->AdvRouteList; - while(route) - { - if (route->PrefixLen > MAX_PrefixLen) - { + while (route) { + if (route->PrefixLen > MAX_PrefixLen) { flog(LOG_ERR, "invalid route prefix length (%u) for %s", route->PrefixLen, iface->Name); res = -1; } diff --git a/log.c b/log.c index f41ef653..f4cbfa7e 100644 --- a/log.c +++ b/log.c @@ -16,57 +16,53 @@ #include "includes.h" #include "radvd.h" -static int log_method = L_NONE; +static int log_method = L_NONE; static char *log_ident; static char *log_file; static FILE *log_file_fd; static int log_facility; static int debug_level = 0; -int -log_open(int method, char *ident, char *log, int facility) +int log_open(int method, char *ident, char *log, int facility) { log_method = method; log_ident = ident; switch (log_method) { - case L_NONE: - case L_STDERR: - break; - case L_STDERR_SYSLOG: - /* fallthrough */ - case L_SYSLOG: - if (facility == -1) - log_facility = LOG_DAEMON; - else - log_facility = facility; - - openlog(log_ident, LOG_PID, log_facility); - break; - case L_LOGFILE: - if (!log) - { - fprintf(stderr, "%s: no logfile specified\n", log_ident); - return (-1); - } - log_file = log; - if ((log_file_fd = fopen(log_file, "a")) == NULL) - { - fprintf(stderr, "%s: can't open %s: %s\n", log_ident, log_file, strerror(errno)); - return (-1); - } - break; - default: - fprintf(stderr, "%s: unknown logging method: %d\n", log_ident, log_method); - log_method = L_NONE; + case L_NONE: + case L_STDERR: + break; + case L_STDERR_SYSLOG: + /* fallthrough */ + case L_SYSLOG: + if (facility == -1) + log_facility = LOG_DAEMON; + else + log_facility = facility; + + openlog(log_ident, LOG_PID, log_facility); + break; + case L_LOGFILE: + if (!log) { + fprintf(stderr, "%s: no logfile specified\n", log_ident); + return (-1); + } + log_file = log; + if ((log_file_fd = fopen(log_file, "a")) == NULL) { + fprintf(stderr, "%s: can't open %s: %s\n", log_ident, log_file, strerror(errno)); return (-1); + } + break; + default: + fprintf(stderr, "%s: unknown logging method: %d\n", log_ident, log_method); + log_method = L_NONE; + return (-1); } return 0; } /* note: [dfv]log() is also called from root context */ -static int -vlog(int prio, char *format, va_list ap) +static int vlog(int prio, char *format, va_list ap) { char tstamp[64], buff[1024]; struct tm *tm; @@ -75,41 +71,40 @@ vlog(int prio, char *format, va_list ap) vsnprintf(buff, sizeof(buff), format, ap); switch (log_method) { - case L_NONE: + case L_NONE: + break; + case L_SYSLOG: + syslog(prio, "%s", buff); + break; + case L_STDERR_SYSLOG: + syslog(prio, "%s", buff); + if (prio > LOG_ERR) /* fall through for messages with high priority */ break; - case L_SYSLOG: - syslog(prio, "%s", buff); - break; - case L_STDERR_SYSLOG: - syslog(prio, "%s", buff); - if (prio > LOG_ERR) /* fall through for messages with high priority */ - break; - case L_STDERR: - current = time(NULL); - tm = localtime(¤t); - (void) strftime(tstamp, sizeof(tstamp), LOG_TIME_FORMAT, tm); - - fprintf(stderr, "[%s] %s: %s\n", tstamp, log_ident, buff); - fflush(stderr); - break; - case L_LOGFILE: - current = time(NULL); - tm = localtime(¤t); - (void) strftime(tstamp, sizeof(tstamp), LOG_TIME_FORMAT, tm); - - fprintf(log_file_fd, "[%s] %s: %s\n", tstamp, log_ident, buff); - fflush(log_file_fd); - break; - default: - fprintf(stderr, "%s: unknown logging method: %d\n", log_ident, log_method); - log_method = L_NONE; - return (-1); + case L_STDERR: + current = time(NULL); + tm = localtime(¤t); + (void)strftime(tstamp, sizeof(tstamp), LOG_TIME_FORMAT, tm); + + fprintf(stderr, "[%s] %s: %s\n", tstamp, log_ident, buff); + fflush(stderr); + break; + case L_LOGFILE: + current = time(NULL); + tm = localtime(¤t); + (void)strftime(tstamp, sizeof(tstamp), LOG_TIME_FORMAT, tm); + + fprintf(log_file_fd, "[%s] %s: %s\n", tstamp, log_ident, buff); + fflush(log_file_fd); + break; + default: + fprintf(stderr, "%s: unknown logging method: %d\n", log_ident, log_method); + log_method = L_NONE; + return (-1); } return 0; } -void -dlog(int prio, int level, char *format, ...) +void dlog(int prio, int level, char *format, ...) { va_list ap; @@ -121,8 +116,7 @@ dlog(int prio, int level, char *format, ...) va_end(ap); } -void -flog(int prio, char *format, ...) +void flog(int prio, char *format, ...) { va_list ap; @@ -131,36 +125,33 @@ flog(int prio, char *format, ...) va_end(ap); } -int -log_close(void) +int log_close(void) { switch (log_method) { - case L_NONE: - case L_STDERR: - break; - case L_STDERR_SYSLOG: - case L_SYSLOG: - closelog(); - break; - case L_LOGFILE: - fclose(log_file_fd); - break; - default: - fprintf(stderr, "%s: unknown logging method: %d\n", log_ident, log_method); - log_method = L_NONE; - return (-1); + case L_NONE: + case L_STDERR: + break; + case L_STDERR_SYSLOG: + case L_SYSLOG: + closelog(); + break; + case L_LOGFILE: + fclose(log_file_fd); + break; + default: + fprintf(stderr, "%s: unknown logging method: %d\n", log_ident, log_method); + log_method = L_NONE; + return (-1); } return 0; } -void -set_debuglevel(int level) +void set_debuglevel(int level) { debug_level = level; } -int -get_debuglevel(void) +int get_debuglevel(void) { return debug_level; } diff --git a/log.h b/log.h index 73521767..76936755 100644 --- a/log.h +++ b/log.h @@ -20,11 +20,10 @@ #define LOG_TIME_FORMAT "%b %d %H:%M:%S" -int log_open(int, char *, char*, int); +int log_open(int, char *, char *, int); void flog(int, char *, ...); void dlog(int, int, char *, ...); int log_close(void); int log_reopen(void); void set_debuglevel(int); int get_debuglevel(void); - diff --git a/netlink.c b/netlink.c index 64d18541..c47b2852 100644 --- a/netlink.c +++ b/netlink.c @@ -40,18 +40,18 @@ void process_netlink_msg(int sock) struct sockaddr_nl sa; struct msghdr msg = { (void *)&sa, sizeof(sa), &iov, 1, NULL, 0, 0 }; struct nlmsghdr *nh; - struct ifinfomsg * ifinfo; + struct ifinfomsg *ifinfo; struct rtattr *rta; int rta_len; - char ifname[IF_NAMESIZE] = {""}; + char ifname[IF_NAMESIZE] = { "" }; int reloaded = 0; - len = recvmsg (sock, &msg, 0); + len = recvmsg(sock, &msg, 0); if (len == -1) { flog(LOG_ERR, "recvmsg failed: %s", strerror(errno)); } - for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len); nh = NLMSG_NEXT (nh, len)) { + for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) { /* The end of multipart message. */ if (nh->nlmsg_type == NLMSG_DONE) return; @@ -71,8 +71,7 @@ void process_netlink_msg(int sock) if (rta->rta_type == IFLA_OPERSTATE || rta->rta_type == IFLA_LINKMODE) { if (ifinfo->ifi_flags & IFF_RUNNING) { dlog(LOG_DEBUG, 3, "%s, ifindex %d, flags is running", ifname, ifinfo->ifi_index); - } - else { + } else { dlog(LOG_DEBUG, 3, "%s, ifindex %d, flags is *NOT* running", ifname, ifinfo->ifi_index); } if (!reloaded) { @@ -96,7 +95,7 @@ int netlink_socket(void) flog(LOG_ERR, "Unable to open netlink socket: %s", strerror(errno)); } #if defined SOL_NETLINK && defined NETLINK_NO_ENOBUFS - else if (setsockopt(sock, SOL_NETLINK, NETLINK_NO_ENOBUFS, &val, sizeof(val)) < 0 ) { + else if (setsockopt(sock, SOL_NETLINK, NETLINK_NO_ENOBUFS, &val, sizeof(val)) < 0) { flog(LOG_ERR, "Unable to setsockopt NETLINK_NO_ENOBUFS: %s", strerror(errno)); } #endif @@ -104,7 +103,7 @@ int netlink_socket(void) snl.nl_family = AF_NETLINK; snl.nl_groups = RTMGRP_LINK; - rc = bind(sock, (struct sockaddr*)&snl, sizeof(snl)); + rc = bind(sock, (struct sockaddr *)&snl, sizeof(snl)); if (rc == -1) { flog(LOG_ERR, "Unable to bind netlink socket: %s", strerror(errno)); close(sock); @@ -113,4 +112,3 @@ int netlink_socket(void) return sock; } - diff --git a/netlink.h b/netlink.h index a950d1dd..cf2a9992 100644 --- a/netlink.h +++ b/netlink.h @@ -17,4 +17,3 @@ void process_netlink_msg(int sock); int netlink_socket(void); - diff --git a/pathnames.h b/pathnames.h index 3b6db165..ae52c387 100644 --- a/pathnames.h +++ b/pathnames.h @@ -40,7 +40,7 @@ #define PROC_SYS_IP6_BASEREACHTIME "/proc/sys/net/ipv6/neigh/%s/base_reachable_time" #define PROC_SYS_IP6_RETRANSTIMER_MS "/proc/sys/net/ipv6/neigh/%s/retrans_time_ms" #define PROC_SYS_IP6_RETRANSTIMER "/proc/sys/net/ipv6/neigh/%s/retrans_time" -#else /* BSD */ +#else /* BSD */ #define SYSCTL_IP6_FORWARDING CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_FORWARDING #endif diff --git a/privsep-linux.c b/privsep-linux.c index af88af73..18929328 100644 --- a/privsep-linux.c +++ b/privsep-linux.c @@ -41,8 +41,7 @@ struct privsep_command { }; /* Privileged read loop */ -void -privsep_read_loop(void) +void privsep_read_loop(void) { struct privsep_command cmd; int ret; @@ -52,8 +51,7 @@ privsep_read_loop(void) if (ret <= 0) { /* Error or EOF, give up */ if (ret < 0) { - flog(LOG_ERR, "Exiting, privsep_read_loop had readn error: %s\n", - strerror(errno)); + flog(LOG_ERR, "Exiting, privsep_read_loop had readn error: %s\n", strerror(errno)); } else { flog(LOG_ERR, "Exiting, privsep_read_loop had readn return 0 bytes\n"); } @@ -65,9 +63,9 @@ privsep_read_loop(void) return; } - cmd.iface[IFNAMSIZ-1] = '\0'; + cmd.iface[IFNAMSIZ - 1] = '\0'; - switch(cmd.type) { + switch (cmd.type) { case SET_INTERFACE_LINKMTU: if (cmd.val < MIN_AdvLinkMTU || cmd.val > MAX_AdvLinkMTU) { @@ -104,7 +102,7 @@ privsep_read_loop(void) ret = set_interface_var(cmd.iface, PROC_SYS_IP6_RETRANSTIMER_MS, "RetransTimer (ms)", cmd.val); if (ret == 0) break; - set_interface_var(cmd.iface, PROC_SYS_IP6_RETRANSTIMER, "RetransTimer", cmd.val / 1000 * USER_HZ); /* XXX user_hz */ + set_interface_var(cmd.iface, PROC_SYS_IP6_RETRANSTIMER, "RetransTimer", cmd.val / 1000 * USER_HZ); /* XXX user_hz */ break; default: @@ -115,8 +113,7 @@ privsep_read_loop(void) } /* Fork to create privileged process connected by a pipe */ -int -privsep_init(void) +int privsep_init(void) { int pipefds[2]; pid_t pid; @@ -166,8 +163,7 @@ privsep_init(void) } /* Interface calls for the unprivileged process */ -int -privsep_interface_linkmtu(const char *iface, uint32_t mtu) +int privsep_interface_linkmtu(const char *iface, uint32_t mtu) { struct privsep_command cmd; cmd.type = SET_INTERFACE_LINKMTU; @@ -179,8 +175,7 @@ privsep_interface_linkmtu(const char *iface, uint32_t mtu) return 0; } -int -privsep_interface_curhlim(const char *iface, uint32_t hlim) +int privsep_interface_curhlim(const char *iface, uint32_t hlim) { struct privsep_command cmd; cmd.type = SET_INTERFACE_CURHLIM; @@ -191,8 +186,7 @@ privsep_interface_curhlim(const char *iface, uint32_t hlim) return 0; } -int -privsep_interface_reachtime(const char *iface, uint32_t rtime) +int privsep_interface_reachtime(const char *iface, uint32_t rtime) { struct privsep_command cmd; cmd.type = SET_INTERFACE_REACHTIME; @@ -203,8 +197,7 @@ privsep_interface_reachtime(const char *iface, uint32_t rtime) return 0; } -int -privsep_interface_retranstimer(const char *iface, uint32_t rettimer) +int privsep_interface_retranstimer(const char *iface, uint32_t rettimer) { struct privsep_command cmd; cmd.type = SET_INTERFACE_RETRANSTIMER; diff --git a/process.c b/process.c index 4c0e5fbf..53a1150c 100644 --- a/process.c +++ b/process.c @@ -17,16 +17,11 @@ #include "includes.h" #include "radvd.h" -static void process_rs(struct Interface *, unsigned char *msg, - int len, struct sockaddr_in6 *); -static void process_ra(struct Interface *, unsigned char *msg, int len, - struct sockaddr_in6 *); -static int addr_match(struct in6_addr *a1, struct in6_addr *a2, - int prefixlen); - -void -process(struct Interface *ifacel, unsigned char *msg, int len, - struct sockaddr_in6 *addr, struct in6_pktinfo *pkt_info, int hoplimit) +static void process_rs(struct Interface *, unsigned char *msg, int len, struct sockaddr_in6 *); +static void process_ra(struct Interface *, unsigned char *msg, int len, struct sockaddr_in6 *); +static int addr_match(struct in6_addr *a1, struct in6_addr *a2, int prefixlen); + +void process(struct Interface *ifacel, unsigned char *msg, int len, struct sockaddr_in6 *addr, struct in6_pktinfo *pkt_info, int hoplimit) { struct Interface *iface; struct icmp6_hdr *icmph; @@ -34,9 +29,8 @@ process(struct Interface *ifacel, unsigned char *msg, int len, print_addr(&addr->sin6_addr, addr_str); - if ( ! pkt_info ) - { - flog(LOG_WARNING, "received packet with no pkt_info from %s!", addr_str ); + if (!pkt_info) { + flog(LOG_WARNING, "received packet with no pkt_info from %s!", addr_str); return; } @@ -44,31 +38,25 @@ process(struct Interface *ifacel, unsigned char *msg, int len, * can this happen? */ - if (len < sizeof(struct icmp6_hdr)) - { - flog(LOG_WARNING, "received icmpv6 packet with invalid length (%d) from %s", - len, addr_str); + if (len < sizeof(struct icmp6_hdr)) { + flog(LOG_WARNING, "received icmpv6 packet with invalid length (%d) from %s", len, addr_str); return; } - icmph = (struct icmp6_hdr *) msg; + icmph = (struct icmp6_hdr *)msg; - if (icmph->icmp6_type != ND_ROUTER_SOLICIT && - icmph->icmp6_type != ND_ROUTER_ADVERT) - { + if (icmph->icmp6_type != ND_ROUTER_SOLICIT && icmph->icmp6_type != ND_ROUTER_ADVERT) { /* - * We just want to listen to RSs and RAs + * We just want to listen to RSs and RAs */ flog(LOG_ERR, "icmpv6 filter failed"); return; } - if (icmph->icmp6_type == ND_ROUTER_ADVERT) - { + if (icmph->icmp6_type == ND_ROUTER_ADVERT) { if (len < sizeof(struct nd_router_advert)) { - flog(LOG_WARNING, "received icmpv6 RA packet with invalid length (%d) from %s", - len, addr_str); + flog(LOG_WARNING, "received icmpv6 RA packet with invalid length (%d) from %s", len, addr_str); return; } @@ -78,19 +66,15 @@ process(struct Interface *ifacel, unsigned char *msg, int len, } } - if (icmph->icmp6_type == ND_ROUTER_SOLICIT) - { + if (icmph->icmp6_type == ND_ROUTER_SOLICIT) { if (len < sizeof(struct nd_router_solicit)) { - flog(LOG_WARNING, "received icmpv6 RS packet with invalid length (%d) from %s", - len, addr_str); + flog(LOG_WARNING, "received icmpv6 RS packet with invalid length (%d) from %s", len, addr_str); return; } } - if (icmph->icmp6_code != 0) - { - flog(LOG_WARNING, "received icmpv6 RS/RA packet with invalid code (%d) from %s", - icmph->icmp6_code, addr_str); + if (icmph->icmp6_code != 0) { + flog(LOG_WARNING, "received icmpv6 RS/RA packet with invalid code (%d) from %s", icmph->icmp6_code, addr_str); return; } @@ -98,52 +82,40 @@ process(struct Interface *ifacel, unsigned char *msg, int len, /* get iface by received if_index */ - for (iface = ifacel; iface; iface=iface->next) - { - if (iface->if_index == pkt_info->ipi6_ifindex) - { + for (iface = ifacel; iface; iface = iface->next) { + if (iface->if_index == pkt_info->ipi6_ifindex) { break; } } - if (iface == NULL) - { - dlog(LOG_DEBUG, 2, "received packet from unknown interface: %d", - pkt_info->ipi6_ifindex); + if (iface == NULL) { + dlog(LOG_DEBUG, 2, "received packet from unknown interface: %d", pkt_info->ipi6_ifindex); return; } - if (hoplimit != 255) - { + if (hoplimit != 255) { print_addr(&addr->sin6_addr, addr_str); - flog(LOG_WARNING, "received RS or RA with invalid hoplimit %d from %s", - hoplimit, addr_str); + flog(LOG_WARNING, "received RS or RA with invalid hoplimit %d from %s", hoplimit, addr_str); return; } - if (!iface->AdvSendAdvert) - { + if (!iface->AdvSendAdvert) { dlog(LOG_DEBUG, 2, "AdvSendAdvert is off for %s", iface->Name); return; } dlog(LOG_DEBUG, 4, "found Interface: %s", iface->Name); - if (icmph->icmp6_type == ND_ROUTER_SOLICIT) - { + if (icmph->icmp6_type == ND_ROUTER_SOLICIT) { dlog(LOG_DEBUG, 4, "received RS from %s", addr_str); process_rs(iface, msg, len, addr); - } - else if (icmph->icmp6_type == ND_ROUTER_ADVERT) - { + } else if (icmph->icmp6_type == ND_ROUTER_ADVERT) { dlog(LOG_DEBUG, 4, "received RA from %s", addr_str); process_ra(iface, msg, len, addr); } } -static void -process_rs(struct Interface *iface, unsigned char *msg, int len, - struct sockaddr_in6 *addr) +static void process_rs(struct Interface *iface, unsigned char *msg, int len, struct sockaddr_in6 *addr) { double delay; double next; @@ -153,33 +125,27 @@ process_rs(struct Interface *iface, unsigned char *msg, int len, /* validation */ len -= sizeof(struct nd_router_solicit); - opt_str = (uint8_t *)(msg + sizeof(struct nd_router_solicit)); + opt_str = (uint8_t *) (msg + sizeof(struct nd_router_solicit)); - while (len > 0) - { + while (len > 0) { int optlen; - if (len < 2) - { + if (len < 2) { flog(LOG_WARNING, "trailing garbage in RS"); return; } optlen = (opt_str[1] << 3); - if (optlen == 0) - { + if (optlen == 0) { flog(LOG_WARNING, "zero length option in RS"); return; - } - else if (optlen > len) - { + } else if (optlen > len) { flog(LOG_WARNING, "option length greater than total length in RS"); return; } - if (*opt_str == ND_OPT_SOURCE_LINKADDR && - IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr)) { + if (*opt_str == ND_OPT_SOURCE_LINKADDR && IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr)) { flog(LOG_WARNING, "received icmpv6 RS packet with unspecified source address and there is a lladdr option"); return; } @@ -190,17 +156,16 @@ process_rs(struct Interface *iface, unsigned char *msg, int len, gettimeofday(&tv, NULL); - delay = MAX_RA_DELAY_TIME * rand() / (RAND_MAX +1.0); + delay = MAX_RA_DELAY_TIME * rand() / (RAND_MAX + 1.0); if (iface->UnicastOnly) { send_ra_forall(iface, &addr->sin6_addr); - } - else if ( timevaldiff(&tv, &iface->last_multicast) / 1000.0 < iface->MinDelayBetweenRAs ) { + } else if (timevaldiff(&tv, &iface->last_multicast) / 1000.0 < iface->MinDelayBetweenRAs) { /* last RA was sent only a few moments ago, don't send another immediately. */ - next = iface->MinDelayBetweenRAs - (tv.tv_sec + tv.tv_usec / 1000000.0) + (iface->last_multicast.tv_sec + iface->last_multicast.tv_usec / 1000000.0) + delay/1000.0; + next = + iface->MinDelayBetweenRAs - (tv.tv_sec + tv.tv_usec / 1000000.0) + (iface->last_multicast.tv_sec + iface->last_multicast.tv_usec / 1000000.0) + delay / 1000.0; iface->next_multicast = next_timeval(next); - } - else { + } else { /* no RA sent in a while, send a multicast reply */ send_ra_forall(iface, NULL); next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval); @@ -211,9 +176,7 @@ process_rs(struct Interface *iface, unsigned char *msg, int len, /* * check router advertisements according to RFC 4861, 6.2.7 */ -static void -process_ra(struct Interface *iface, unsigned char *msg, int len, - struct sockaddr_in6 *addr) +static void process_ra(struct Interface *iface, unsigned char *msg, int len, struct sockaddr_in6 *addr) { struct nd_router_advert *radvert; char addr_str[INET6_ADDRSTRLEN]; @@ -221,41 +184,28 @@ process_ra(struct Interface *iface, unsigned char *msg, int len, print_addr(&addr->sin6_addr, addr_str); - radvert = (struct nd_router_advert *) msg; + radvert = (struct nd_router_advert *)msg; - if ((radvert->nd_ra_curhoplimit && iface->AdvCurHopLimit) && - (radvert->nd_ra_curhoplimit != iface->AdvCurHopLimit)) - { - flog(LOG_WARNING, "our AdvCurHopLimit on %s doesn't agree with %s", - iface->Name, addr_str); + if ((radvert->nd_ra_curhoplimit && iface->AdvCurHopLimit) && (radvert->nd_ra_curhoplimit != iface->AdvCurHopLimit)) { + flog(LOG_WARNING, "our AdvCurHopLimit on %s doesn't agree with %s", iface->Name, addr_str); } - if ((radvert->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) && !iface->AdvManagedFlag) - { - flog(LOG_WARNING, "our AdvManagedFlag on %s doesn't agree with %s", - iface->Name, addr_str); + if ((radvert->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) && !iface->AdvManagedFlag) { + flog(LOG_WARNING, "our AdvManagedFlag on %s doesn't agree with %s", iface->Name, addr_str); } - if ((radvert->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) && !iface->AdvOtherConfigFlag) - { - flog(LOG_WARNING, "our AdvOtherConfigFlag on %s doesn't agree with %s", - iface->Name, addr_str); + if ((radvert->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) && !iface->AdvOtherConfigFlag) { + flog(LOG_WARNING, "our AdvOtherConfigFlag on %s doesn't agree with %s", iface->Name, addr_str); } /* note: we don't check the default router preference here, because they're likely different */ - if ((radvert->nd_ra_reachable && iface->AdvReachableTime) && - (ntohl(radvert->nd_ra_reachable) != iface->AdvReachableTime)) - { - flog(LOG_WARNING, "our AdvReachableTime on %s doesn't agree with %s", - iface->Name, addr_str); + if ((radvert->nd_ra_reachable && iface->AdvReachableTime) && (ntohl(radvert->nd_ra_reachable) != iface->AdvReachableTime)) { + flog(LOG_WARNING, "our AdvReachableTime on %s doesn't agree with %s", iface->Name, addr_str); } - if ((radvert->nd_ra_retransmit && iface->AdvRetransTimer) && - (ntohl(radvert->nd_ra_retransmit) != iface->AdvRetransTimer)) - { - flog(LOG_WARNING, "our AdvRetransTimer on %s doesn't agree with %s", - iface->Name, addr_str); + if ((radvert->nd_ra_retransmit && iface->AdvRetransTimer) && (ntohl(radvert->nd_ra_retransmit) != iface->AdvRetransTimer)) { + flog(LOG_WARNING, "our AdvRetransTimer on %s doesn't agree with %s", iface->Name, addr_str); } len -= sizeof(struct nd_router_advert); @@ -263,10 +213,9 @@ process_ra(struct Interface *iface, unsigned char *msg, int len, if (len == 0) return; - opt_str = (uint8_t *)(msg + sizeof(struct nd_router_advert)); + opt_str = (uint8_t *) (msg + sizeof(struct nd_router_advert)); - while (len > 0) - { + while (len > 0) { int optlen; struct nd_opt_prefix_info *pinfo; struct nd_opt_rdnss_info_local *rdnssinfo; @@ -280,77 +229,49 @@ process_ra(struct Interface *iface, unsigned char *msg, int len, unsigned int offset, label_len; uint32_t preferred, valid, count; - if (len < 2) - { - flog(LOG_ERR, "trailing garbage in RA on %s from %s", - iface->Name, addr_str); + if (len < 2) { + flog(LOG_ERR, "trailing garbage in RA on %s from %s", iface->Name, addr_str); break; } optlen = (opt_str[1] << 3); - if (optlen == 0) - { - flog(LOG_ERR, "zero length option in RA on %s from %s", - iface->Name, addr_str); + if (optlen == 0) { + flog(LOG_ERR, "zero length option in RA on %s from %s", iface->Name, addr_str); break; - } - else if (optlen > len) - { - flog(LOG_ERR, "option length (%d) greater than total" - " length (%d) in RA on %s from %s", - optlen, len, - iface->Name, addr_str); + } else if (optlen > len) { + flog(LOG_ERR, "option length (%d) greater than total" " length (%d) in RA on %s from %s", optlen, len, iface->Name, addr_str); break; } - switch (*opt_str) - { + switch (*opt_str) { case ND_OPT_MTU: mtu = (struct nd_opt_mtu *)opt_str; if (len < sizeof(*mtu)) return; - if (iface->AdvLinkMTU && (ntohl(mtu->nd_opt_mtu_mtu) != iface->AdvLinkMTU)) - { - flog(LOG_WARNING, "our AdvLinkMTU on %s doesn't agree with %s", - iface->Name, addr_str); + if (iface->AdvLinkMTU && (ntohl(mtu->nd_opt_mtu_mtu) != iface->AdvLinkMTU)) { + flog(LOG_WARNING, "our AdvLinkMTU on %s doesn't agree with %s", iface->Name, addr_str); } break; case ND_OPT_PREFIX_INFORMATION: - pinfo = (struct nd_opt_prefix_info *) opt_str; + pinfo = (struct nd_opt_prefix_info *)opt_str; if (len < sizeof(*pinfo)) return; preferred = ntohl(pinfo->nd_opt_pi_preferred_time); valid = ntohl(pinfo->nd_opt_pi_valid_time); prefix = iface->AdvPrefixList; - while (prefix) - { + while (prefix) { if (prefix->enabled && - (prefix->PrefixLen == pinfo->nd_opt_pi_prefix_len) && - addr_match(&prefix->Prefix, &pinfo->nd_opt_pi_prefix, - prefix->PrefixLen)) - { + (prefix->PrefixLen == pinfo->nd_opt_pi_prefix_len) && addr_match(&prefix->Prefix, &pinfo->nd_opt_pi_prefix, prefix->PrefixLen)) { print_addr(&prefix->Prefix, prefix_str); - if (!prefix->DecrementLifetimesFlag && valid != prefix->AdvValidLifetime) - { - flog(LOG_WARNING, "our AdvValidLifetime on" - " %s for %s doesn't agree with %s", - iface->Name, - prefix_str, - addr_str - ); + if (!prefix->DecrementLifetimesFlag && valid != prefix->AdvValidLifetime) { + flog(LOG_WARNING, "our AdvValidLifetime on" " %s for %s doesn't agree with %s", iface->Name, prefix_str, addr_str); } - if (!prefix->DecrementLifetimesFlag && preferred != prefix->AdvPreferredLifetime) - { - flog(LOG_WARNING, "our AdvPreferredLifetime on" - " %s for %s doesn't agree with %s", - iface->Name, - prefix_str, - addr_str - ); + if (!prefix->DecrementLifetimesFlag && preferred != prefix->AdvPreferredLifetime) { + flog(LOG_WARNING, "our AdvPreferredLifetime on" " %s for %s doesn't agree with %s", iface->Name, prefix_str, addr_str); } } @@ -365,63 +286,58 @@ process_ra(struct Interface *iface, unsigned char *msg, int len, break; case ND_OPT_TARGET_LINKADDR: case ND_OPT_REDIRECTED_HEADER: - flog(LOG_ERR, "invalid option %d in RA on %s from %s", - (int)*opt_str, iface->Name, addr_str); + flog(LOG_ERR, "invalid option %d in RA on %s from %s", (int)*opt_str, iface->Name, addr_str); break; - /* Mobile IPv6 extensions */ + /* Mobile IPv6 extensions */ case ND_OPT_RTR_ADV_INTERVAL: case ND_OPT_HOME_AGENT_INFO: /* not checked */ break; case ND_OPT_RDNSS_INFORMATION: - rdnssinfo = (struct nd_opt_rdnss_info_local *) opt_str; + rdnssinfo = (struct nd_opt_rdnss_info_local *)opt_str; if (len < sizeof(*rdnssinfo)) return; count = rdnssinfo->nd_opt_rdnssi_len; /* Check the RNDSS addresses received */ switch (count) { - case 7: - rdnss = iface->AdvRDNSSList; - if (!check_rdnss_presence(rdnss, &rdnssinfo->nd_opt_rdnssi_addr3 )) { - /* no match found in iface->AdvRDNSSList */ - print_addr(&rdnssinfo->nd_opt_rdnssi_addr3, rdnss_str); - flog(LOG_WARNING, "RDNSS address %s received on %s from %s is not advertised by us", - rdnss_str, iface->Name, addr_str); - } - /* FALLTHROUGH */ - case 5: - rdnss = iface->AdvRDNSSList; - if (!check_rdnss_presence(rdnss, &rdnssinfo->nd_opt_rdnssi_addr2 )) { - /* no match found in iface->AdvRDNSSList */ - print_addr(&rdnssinfo->nd_opt_rdnssi_addr2, rdnss_str); - flog(LOG_WARNING, "RDNSS address %s received on %s from %s is not advertised by us", - rdnss_str, iface->Name, addr_str); - } - /* FALLTHROUGH */ - case 3: - rdnss = iface->AdvRDNSSList; - if (!check_rdnss_presence(rdnss, &rdnssinfo->nd_opt_rdnssi_addr1 )) { - /* no match found in iface->AdvRDNSSList */ - print_addr(&rdnssinfo->nd_opt_rdnssi_addr1, rdnss_str); - flog(LOG_WARNING, "RDNSS address %s received on %s from %s is not advertised by us", - rdnss_str, iface->Name, addr_str); - } + case 7: + rdnss = iface->AdvRDNSSList; + if (!check_rdnss_presence(rdnss, &rdnssinfo->nd_opt_rdnssi_addr3)) { + /* no match found in iface->AdvRDNSSList */ + print_addr(&rdnssinfo->nd_opt_rdnssi_addr3, rdnss_str); + flog(LOG_WARNING, "RDNSS address %s received on %s from %s is not advertised by us", rdnss_str, iface->Name, addr_str); + } + /* FALLTHROUGH */ + case 5: + rdnss = iface->AdvRDNSSList; + if (!check_rdnss_presence(rdnss, &rdnssinfo->nd_opt_rdnssi_addr2)) { + /* no match found in iface->AdvRDNSSList */ + print_addr(&rdnssinfo->nd_opt_rdnssi_addr2, rdnss_str); + flog(LOG_WARNING, "RDNSS address %s received on %s from %s is not advertised by us", rdnss_str, iface->Name, addr_str); + } + /* FALLTHROUGH */ + case 3: + rdnss = iface->AdvRDNSSList; + if (!check_rdnss_presence(rdnss, &rdnssinfo->nd_opt_rdnssi_addr1)) { + /* no match found in iface->AdvRDNSSList */ + print_addr(&rdnssinfo->nd_opt_rdnssi_addr1, rdnss_str); + flog(LOG_WARNING, "RDNSS address %s received on %s from %s is not advertised by us", rdnss_str, iface->Name, addr_str); + } - break; - default: - flog(LOG_ERR, "invalid len %i in RDNSS option on %s from %s", - count, iface->Name, addr_str); + break; + default: + flog(LOG_ERR, "invalid len %i in RDNSS option on %s from %s", count, iface->Name, addr_str); } break; case ND_OPT_DNSSL_INFORMATION: - dnsslinfo = (struct nd_opt_dnssl_info_local *) opt_str; + dnsslinfo = (struct nd_opt_dnssl_info_local *)opt_str; if (len < sizeof(*dnsslinfo)) return; suffix[0] = '\0'; - for (offset = 0; offset < (dnsslinfo->nd_opt_dnssli_len-1)*8;) { + for (offset = 0; offset < (dnsslinfo->nd_opt_dnssli_len - 1) * 8;) { if (&dnsslinfo->nd_opt_dnssli_suffixes[offset] - opt_str >= len) return; label_len = dnsslinfo->nd_opt_dnssli_suffixes[offset++]; @@ -435,8 +351,7 @@ process_ra(struct Interface *iface, unsigned char *msg, int len, continue; if (!check_dnssl_presence(iface->AdvDNSSLList, suffix)) { - flog(LOG_WARNING, "DNSSL suffix %s received on %s from %s is not advertised by us", - suffix, iface->Name, addr_str); + flog(LOG_WARNING, "DNSSL suffix %s received on %s from %s is not advertised by us", suffix, iface->Name, addr_str); } suffix[0] = '\0'; @@ -448,23 +363,19 @@ process_ra(struct Interface *iface, unsigned char *msg, int len, * 2) last byte of dnssli_suffix must not overflow opt_str + len */ if ((sizeof(suffix) - strlen(suffix)) < (label_len + 2) || - label_len > label_len + 2 || - &dnsslinfo->nd_opt_dnssli_suffixes[offset+label_len] - opt_str >= len || - offset + label_len < offset) { - flog(LOG_ERR, "oversized suffix in DNSSL option on %s from %s", - iface->Name, addr_str); + label_len > label_len + 2 || &dnsslinfo->nd_opt_dnssli_suffixes[offset + label_len] - opt_str >= len || offset + label_len < offset) { + flog(LOG_ERR, "oversized suffix in DNSSL option on %s from %s", iface->Name, addr_str); break; } if (suffix[0] != '\0') strcat(suffix, "."); - strncat(suffix, (char*)&dnsslinfo->nd_opt_dnssli_suffixes[offset], label_len); + strncat(suffix, (char *)&dnsslinfo->nd_opt_dnssli_suffixes[offset], label_len); offset += label_len; } break; default: - dlog(LOG_DEBUG, 1, "unknown option %d in RA on %s from %s", - (int)*opt_str, iface->Name, addr_str); + dlog(LOG_DEBUG, 1, "unknown option %d in RA on %s from %s", (int)*opt_str, iface->Name, addr_str); break; } @@ -473,28 +384,25 @@ process_ra(struct Interface *iface, unsigned char *msg, int len, } } -static int -addr_match(struct in6_addr *a1, struct in6_addr *a2, int prefixlen) +static int addr_match(struct in6_addr *a1, struct in6_addr *a2, int prefixlen) { unsigned int pdw; unsigned int pbi; - pdw = prefixlen >> 0x05; /* num of whole uint32_t in prefix */ - pbi = prefixlen & 0x1f; /* num of bits in incomplete uint32_t in prefix */ + pdw = prefixlen >> 0x05; /* num of whole uint32_t in prefix */ + pbi = prefixlen & 0x1f; /* num of bits in incomplete uint32_t in prefix */ - if (pdw) - { + if (pdw) { if (memcmp(a1, a2, pdw << 2)) return 0; } - if (pbi) - { + if (pbi) { uint32_t w1, w2; uint32_t mask; - w1 = *((uint32_t *)a1 + pdw); - w2 = *((uint32_t *)a2 + pdw); + w1 = *((uint32_t *) a1 + pdw); + w2 = *((uint32_t *) a2 + pdw); mask = htonl(((uint32_t) 0xffffffff) << (0x20 - pbi)); @@ -504,4 +412,3 @@ addr_match(struct in6_addr *a1, struct in6_addr *a2, int prefixlen) return 1; } - diff --git a/radvd.c b/radvd.c index 7cadf164..6254b5e1 100644 --- a/radvd.c +++ b/radvd.c @@ -31,23 +31,20 @@ struct Interface *IfaceList = NULL; #ifdef HAVE_GETOPT_LONG char usage_str[] = { -"\n" -" -c, --configtest Parse the config file and exit.\n" -" -C, --config=PATH Sets the config file. Default is /etc/radvd.conf.\n" -" -d, --debug=NUM Sets the debug level. Values can be 1, 2, 3, 4 or 5.\n" -" -f, --facility=NUM Sets the logging facility.\n" -" -h, --help Show this help screen.\n" -" -l, --logfile=PATH Sets the log file.\n" -" -m, --logmethod=X Sets the log method to one of: syslog, stderr, stderr_syslog, logfile, or none.\n" -" -p, --pidfile=PATH Sets the pid file.\n" -" -t, --chrootdir=PATH Chroot to the specified path.\n" -" -u, --username=USER Switch to the specified user.\n" -" -n, --nodaemon Prevent the daemonizing.\n" + "\n" " -c, --configtest Parse the config file and exit.\n" + " -C, --config=PATH Sets the config file. Default is /etc/radvd.conf.\n" + " -d, --debug=NUM Sets the debug level. Values can be 1, 2, 3, 4 or 5.\n" + " -f, --facility=NUM Sets the logging facility.\n" + " -h, --help Show this help screen.\n" + " -l, --logfile=PATH Sets the log file.\n" + " -m, --logmethod=X Sets the log method to one of: syslog, stderr, stderr_syslog, logfile, or none.\n" + " -p, --pidfile=PATH Sets the pid file.\n" + " -t, --chrootdir=PATH Chroot to the specified path.\n" + " -u, --username=USER Switch to the specified user.\n" " -n, --nodaemon Prevent the daemonizing.\n" #ifdef HAVE_NETLINK -" -L, --disablenetlink Disable netlink feature\n" + " -L, --disablenetlink Disable netlink feature\n" #endif -" -I, --disableigmp6check Disable igmp6 check before send\n" -" -v, --version Print the version and quit.\n" + " -I, --disableigmp6check Disable igmp6 check before send\n" " -v, --version Print the version and quit.\n" }; struct option prog_opt[] = { @@ -73,9 +70,7 @@ struct option prog_opt[] = { #else -char usage_str[] = - "[-hsvcn] [-d level] [-C config_file] [-m log_method] [-l log_file]\n" - "\t[-f facility] [-p pid_file] [-u username] [-t chrootdir]"; +char usage_str[] = "[-hsvcn] [-d level] [-C config_file] [-m log_method] [-l log_file]\n" "\t[-f facility] [-p pid_file] [-u username] [-t chrootdir]"; #endif @@ -111,8 +106,7 @@ int check_conffile_perm(const char *, const char *); const char *get_pidfile(void); void main_loop(void); -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int c, log_method; char *logfile; @@ -126,7 +120,7 @@ main(int argc, char *argv[]) #endif pid_t pid; - pname = ((pname=strrchr(argv[0],'/')) != NULL)?pname+1:argv[0]; + pname = ((pname = strrchr(argv[0], '/')) != NULL) ? pname + 1 : argv[0]; srand((unsigned int)time(NULL)); @@ -161,28 +155,17 @@ main(int argc, char *argv[]) pidfile = optarg; break; case 'm': - if (!strcmp(optarg, "syslog")) - { + if (!strcmp(optarg, "syslog")) { log_method = L_SYSLOG; - } - else if (!strcmp(optarg, "stderr_syslog")) - { + } else if (!strcmp(optarg, "stderr_syslog")) { log_method = L_STDERR_SYSLOG; - } - else if (!strcmp(optarg, "stderr")) - { + } else if (!strcmp(optarg, "stderr")) { log_method = L_STDERR; - } - else if (!strcmp(optarg, "logfile")) - { + } else if (!strcmp(optarg, "logfile")) { log_method = L_LOGFILE; - } - else if (!strcmp(optarg, "none")) - { + } else if (!strcmp(optarg, "none")) { log_method = L_NONE; - } - else - { + } else { fprintf(stderr, "%s: unknown log method: %s\n", pname, optarg); exit(1); } @@ -217,8 +200,7 @@ main(int argc, char *argv[]) usage(); #ifdef HAVE_GETOPT_LONG case ':': - fprintf(stderr, "%s: option %s: parameter expected\n", pname, - prog_opt[opt_idx].name); + fprintf(stderr, "%s: option %s: parameter expected\n", pname, prog_opt[opt_idx].name); exit(1); #endif case '?': @@ -234,12 +216,12 @@ main(int argc, char *argv[]) if (chroot(chrootdir) == -1) { perror("chroot"); - exit (1); + exit(1); } if (chdir("/") == -1) { perror("chdir"); - exit (1); + exit(1); } /* username will be switched later */ } @@ -265,14 +247,13 @@ main(int argc, char *argv[]) } /* check that 'other' cannot write the file - * for non-root, also that self/own group can't either - */ + * for non-root, also that self/own group can't either + */ if (check_conffile_perm(username, conf_file) < 0) { if (get_debuglevel() == 0) { flog(LOG_ERR, "Exiting, permissions on conf_file invalid.\n"); exit(1); - } - else + } else flog(LOG_WARNING, "Insecure file permissions, but continuing anyway"); } @@ -291,7 +272,6 @@ main(int argc, char *argv[]) fprintf(stderr, "Syntax OK\n"); exit(0); } - #ifdef USE_PRIVSEP dlog(LOG_DEBUG, 3, "Initializing privsep"); if (privsep_init() < 0) { @@ -345,8 +325,7 @@ main(int argc, char *argv[]) exit(1); } if (daemon_pid_file_create()) { - flog(LOG_ERR, "Cannot create radvd PID file, terminating: %s", - strerror(errno)); + flog(LOG_ERR, "Cannot create radvd PID file, terminating: %s", strerror(errno)); daemon_retval_send(2); exit(1); } @@ -354,7 +333,7 @@ main(int argc, char *argv[]) } /* - * config signal handlers + * config signal handlers */ signal(SIGHUP, sighup_handler); signal(SIGTERM, sigterm_handler); @@ -374,8 +353,8 @@ main(int argc, char *argv[]) return 0; } - -const char *get_pidfile(void) { +const char *get_pidfile(void) +{ return pidfile; } @@ -393,7 +372,7 @@ void main_loop(void) if (!disablenetlink) { fds[1].fd = netlink_socket(); fds[1].events = POLLIN; - } else{ + } else { fds[1].fd = -1; fds[1].events = 0; } @@ -423,15 +402,14 @@ void main_loop(void) } } - dlog(LOG_DEBUG, 5, "polling for %g seconds.", timeout/1000.0); + dlog(LOG_DEBUG, 5, "polling for %g seconds.", timeout / 1000.0); - rc = poll(fds, sizeof(fds)/sizeof(fds[0]), timeout); + rc = poll(fds, sizeof(fds) / sizeof(fds[0]), timeout); if (rc > 0) { if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { flog(LOG_WARNING, "socket error on fds[0].fd"); - } - else if (fds[0].revents & POLLIN) { + } else if (fds[0].revents & POLLIN) { int len, hoplimit; struct sockaddr_in6 rcv_addr; struct in6_pktinfo *pkt_info = NULL; @@ -439,8 +417,7 @@ void main_loop(void) len = recv_rs_ra(msg, &rcv_addr, &pkt_info, &hoplimit); if (len > 0) { - process(IfaceList, msg, len, - &rcv_addr, pkt_info, hoplimit); + process(IfaceList, msg, len, &rcv_addr, pkt_info, hoplimit); } } #ifdef HAVE_NETLINK @@ -452,12 +429,10 @@ void main_loop(void) } } #endif - } - else if ( rc == 0 ) { + } else if (rc == 0) { if (next) timer_handler(next); - } - else if ( rc == -1 ) { + } else if (rc == -1) { dlog(LOG_INFO, 3, "poll returned early: %s", strerror(errno)); } @@ -466,15 +441,13 @@ void main_loop(void) break; } - if (sighup_received) - { + if (sighup_received) { dlog(LOG_INFO, 3, "sig hup received.\n"); reload_config(); sighup_received = 0; } - if (sigusr1_received) - { + if (sigusr1_received) { dlog(LOG_INFO, 3, "sig usr1 received.\n"); reset_prefix_lifetimes(); sigusr1_received = 0; @@ -483,10 +456,9 @@ void main_loop(void) } } -void -timer_handler(void *data) +void timer_handler(void *data) { - struct Interface *iface = (struct Interface *) data; + struct Interface *iface = (struct Interface *)data; double next; dlog(LOG_DEBUG, 4, "timer_handler called for %s", iface->Name); @@ -497,8 +469,7 @@ timer_handler(void *data) next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval); - if (iface->init_racount < MAX_INITIAL_RTR_ADVERTISEMENTS) - { + if (iface->init_racount < MAX_INITIAL_RTR_ADVERTISEMENTS) { iface->init_racount++; next = min(MAX_INITIAL_RTR_ADVERT_INTERVAL, next); } @@ -506,12 +477,10 @@ timer_handler(void *data) iface->next_multicast = next_timeval(next); } -void -config_interface(void) +void config_interface(void) { struct Interface *iface; - for(iface=IfaceList; iface; iface=iface->next) - { + for (iface = IfaceList; iface; iface = iface->next) { if (iface->AdvLinkMTU) set_interface_linkmtu(iface->Name, iface->AdvLinkMTU); if (iface->AdvCurHopLimit) @@ -523,23 +492,20 @@ config_interface(void) } } -void -kickoff_adverts(void) +void kickoff_adverts(void) { struct Interface *iface; /* - * send initial advertisement and set timers + * send initial advertisement and set timers */ - for(iface=IfaceList; iface; iface=iface->next) - { + for (iface = IfaceList; iface; iface = iface->next) { double next; - gettimeofday(&iface->last_ra_time, NULL); - if( iface->UnicastOnly ) + if (iface->UnicastOnly) continue; gettimeofday(&iface->last_multicast, NULL); @@ -559,17 +525,16 @@ kickoff_adverts(void) } } -void -stop_adverts(void) +void stop_adverts(void) { struct Interface *iface; /* - * send final RA (a SHOULD in RFC4861 section 6.2.5) + * send final RA (a SHOULD in RFC4861 section 6.2.5) */ - for (iface=IfaceList; iface; iface=iface->next) { - if( ! iface->UnicastOnly ) { + for (iface = IfaceList; iface; iface = iface->next) { + if (!iface->UnicastOnly) { /* TODO: AdvSendAdvert is being checked in send_ra now so it can be removed here. */ if (iface->AdvSendAdvert) { /* send a final advertisement with zero Router Lifetime */ @@ -586,9 +551,8 @@ void reload_config(void) flog(LOG_INFO, "attempting to reread config file"); - iface=IfaceList; - while(iface) - { + iface = IfaceList; + while (iface) { struct Interface *next_iface = iface->next; struct AdvPrefix *prefix; struct AdvRoute *route; @@ -598,8 +562,7 @@ void reload_config(void) dlog(LOG_DEBUG, 4, "freeing interface %s", iface->Name); prefix = iface->AdvPrefixList; - while (prefix) - { + while (prefix) { struct AdvPrefix *next_prefix = prefix->next; free(prefix); @@ -607,8 +570,7 @@ void reload_config(void) } route = iface->AdvRouteList; - while (route) - { + while (route) { struct AdvRoute *next_route = route->next; free(route); @@ -616,8 +578,7 @@ void reload_config(void) } rdnss = iface->AdvRDNSSList; - while (rdnss) - { + while (rdnss) { struct AdvRDNSS *next_rdnss = rdnss->next; free(rdnss); @@ -625,8 +586,7 @@ void reload_config(void) } dnssl = iface->AdvDNSSLList; - while (dnssl) - { + while (dnssl) { struct AdvDNSSL *next_dnssl = dnssl->next; int i; @@ -657,8 +617,7 @@ void reload_config(void) flog(LOG_INFO, "resuming normal operation"); } -void -sighup_handler(int sig) +void sighup_handler(int sig) { /* Linux has "one-shot" signals, reinstall the signal handler */ signal(SIGHUP, sighup_handler); @@ -666,28 +625,26 @@ sighup_handler(int sig) sighup_received = 1; } -void -sigterm_handler(int sig) +void sigterm_handler(int sig) { /* Linux has "one-shot" signals, reinstall the signal handler */ signal(SIGTERM, sigterm_handler); ++sigterm_received; - if(sigterm_received > 1){ + if (sigterm_received > 1) { abort(); } } -void -sigint_handler(int sig) +void sigint_handler(int sig) { /* Linux has "one-shot" signals, reinstall the signal handler */ signal(SIGINT, sigint_handler); ++sigint_received; - if(sigint_received > 1){ + if (sigint_received > 1) { abort(); } } @@ -706,51 +663,42 @@ void reset_prefix_lifetimes(void) struct AdvPrefix *prefix; char pfx_str[INET6_ADDRSTRLEN]; - flog(LOG_INFO, "Resetting prefix lifetimes"); - - for (iface = IfaceList; iface; iface = iface->next) - { - for (prefix = iface->AdvPrefixList; prefix; - prefix = prefix->next) - { - if (prefix->DecrementLifetimesFlag) - { + + for (iface = IfaceList; iface; iface = iface->next) { + for (prefix = iface->AdvPrefixList; prefix; prefix = prefix->next) { + if (prefix->DecrementLifetimesFlag) { print_addr(&prefix->Prefix, pfx_str); - dlog(LOG_DEBUG, 4, "%s/%u%%%s plft reset from %u to %u secs", pfx_str, prefix->PrefixLen, iface->Name, prefix->curr_preferredlft, prefix->AdvPreferredLifetime); - dlog(LOG_DEBUG, 4, "%s/%u%%%s vlft reset from %u to %u secs", pfx_str, prefix->PrefixLen, iface->Name, prefix->curr_validlft, prefix->AdvValidLifetime); - prefix->curr_validlft = - prefix->AdvValidLifetime; - prefix->curr_preferredlft = - prefix->AdvPreferredLifetime; + dlog(LOG_DEBUG, 4, "%s/%u%%%s plft reset from %u to %u secs", pfx_str, prefix->PrefixLen, iface->Name, prefix->curr_preferredlft, + prefix->AdvPreferredLifetime); + dlog(LOG_DEBUG, 4, "%s/%u%%%s vlft reset from %u to %u secs", pfx_str, prefix->PrefixLen, iface->Name, prefix->curr_validlft, + prefix->AdvValidLifetime); + prefix->curr_validlft = prefix->AdvValidLifetime; + prefix->curr_preferredlft = prefix->AdvPreferredLifetime; } } - + } } -int -drop_root_privileges(const char *username) +int drop_root_privileges(const char *username) { struct passwd *pw = NULL; pw = getpwnam(username); if (pw) { if (initgroups(username, pw->pw_gid) != 0 || setgid(pw->pw_gid) != 0 || setuid(pw->pw_uid) != 0) { - flog(LOG_ERR, "Couldn't change to '%.32s' uid=%d gid=%d", - username, pw->pw_uid, pw->pw_gid); + flog(LOG_ERR, "Couldn't change to '%.32s' uid=%d gid=%d", username, pw->pw_uid, pw->pw_gid); return (-1); } - } - else { + } else { flog(LOG_ERR, "Couldn't find user '%.32s'", username); return (-1); } return 0; } -int -check_conffile_perm(const char *username, const char *conf_file) +int check_conffile_perm(const char *username, const char *conf_file) { struct stat stbuf; struct passwd *pw = NULL; @@ -771,23 +719,20 @@ check_conffile_perm(const char *username, const char *conf_file) return (-1); if (stbuf.st_mode & S_IWOTH) { - flog(LOG_ERR, "Insecure file permissions (writable by others): %s", conf_file); + flog(LOG_ERR, "Insecure file permissions (writable by others): %s", conf_file); return (-1); - } + } /* for non-root: must not be writable by self/own group */ - if (strncmp(username, "root", 5) != 0 && - ((stbuf.st_mode & S_IWGRP && pw->pw_gid == stbuf.st_gid) || - (stbuf.st_mode & S_IWUSR && pw->pw_uid == stbuf.st_uid))) { - flog(LOG_ERR, "Insecure file permissions (writable by self/group): %s", conf_file); + if (strncmp(username, "root", 5) != 0 && ((stbuf.st_mode & S_IWGRP && pw->pw_gid == stbuf.st_gid) || (stbuf.st_mode & S_IWUSR && pw->pw_uid == stbuf.st_uid))) { + flog(LOG_ERR, "Insecure file permissions (writable by self/group): %s", conf_file); return (-1); - } + } - return 0; + return 0; } -int -check_ip6_forwarding(void) +int check_ip6_forwarding(void) { #ifdef HAVE_SYS_SYSCTL_H int forw_sysctl[] = { SYSCTL_IP6_FORWARDING }; @@ -801,64 +746,56 @@ check_ip6_forwarding(void) fp = fopen(PROC_SYS_IP6_FORWARDING, "r"); if (fp) { int rc = fscanf(fp, "%d", &value); - if(rc != 1){ + if (rc != 1) { flog(LOG_ERR, "cannot read value from %s: %s", PROC_SYS_IP6_FORWARDING, strerror(errno)); exit(1); } fclose(fp); - } - else { - flog(LOG_DEBUG, "Correct IPv6 forwarding procfs entry not found, " - "perhaps the procfs is disabled, " - "or the kernel interface has changed?"); + } else { + flog(LOG_DEBUG, "Correct IPv6 forwarding procfs entry not found, " "perhaps the procfs is disabled, " "or the kernel interface has changed?"); value = -1; } -#endif /* __linux__ */ +#endif /* __linux__ */ #ifdef HAVE_SYS_SYSCTL_H - if (!fp && sysctl(forw_sysctl, sizeof(forw_sysctl)/sizeof(forw_sysctl[0]), - &value, &size, NULL, 0) < 0) { - flog(LOG_DEBUG, "Correct IPv6 forwarding sysctl branch not found, " - "perhaps the kernel interface has changed?"); - return(0); /* this is of advisory value only */ + if (!fp && sysctl(forw_sysctl, sizeof(forw_sysctl) / sizeof(forw_sysctl[0]), &value, &size, NULL, 0) < 0) { + flog(LOG_DEBUG, "Correct IPv6 forwarding sysctl branch not found, " "perhaps the kernel interface has changed?"); + return (0); /* this is of advisory value only */ } #endif #ifdef __linux__ - /* Linux allows the forwarding value to be either 1 or 2. - * https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/ip-sysctl.txt?id=ae8abfa00efb8ec550f772cbd1e1854977d06212#n1078 - * - * The value 2 indicates forwarding is enabled and that *AS* *WELL* router solicitions are being done. - * - * Which is sometimes used on routers performing RS on their WAN (ppp, etc.) links - */ + /* Linux allows the forwarding value to be either 1 or 2. + * https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/ip-sysctl.txt?id=ae8abfa00efb8ec550f772cbd1e1854977d06212#n1078 + * + * The value 2 indicates forwarding is enabled and that *AS* *WELL* router solicitions are being done. + * + * Which is sometimes used on routers performing RS on their WAN (ppp, etc.) links + */ if (!warned && value != 1 && value != 2) { warned = 1; flog(LOG_DEBUG, "IPv6 forwarding setting is: %u, should be 1 or 2", value); - return(-1); + return (-1); } #else if (!warned && value != 1) { warned = 1; flog(LOG_DEBUG, "IPv6 forwarding setting is: %u, should be 1", value); - return(-1); + return (-1); } -#endif /* __linux__ */ +#endif /* __linux__ */ - return(0); + return (0); } -int -readin_config(char *fname) +int readin_config(char *fname) { - if ((yyin = fopen(fname, "r")) == NULL) - { + if ((yyin = fopen(fname, "r")) == NULL) { flog(LOG_ERR, "can't open %s: %s", fname, strerror(errno)); return (-1); } - if (yyparse() != 0) - { + if (yyparse() != 0) { flog(LOG_ERR, "error parsing or activating the config file: %s", fname); return (-1); } @@ -867,8 +804,7 @@ readin_config(char *fname) return 0; } -void -version(void) +void version(void) { fprintf(stderr, "Version: %s\n\n", VERSION); fprintf(stderr, "Compiled in settings:\n"); @@ -876,16 +812,13 @@ version(void) fprintf(stderr, " default pidfile \"%s\"\n", PATH_RADVD_PID); fprintf(stderr, " default logfile \"%s\"\n", PATH_RADVD_LOG); fprintf(stderr, " default syslog facility %d\n", LOG_FACILITY); - fprintf(stderr, "Please send bug reports or suggestions to %s.\n", - CONTACT_EMAIL); + fprintf(stderr, "Please send bug reports or suggestions to %s.\n", CONTACT_EMAIL); exit(1); } -void -usage(void) +void usage(void) { fprintf(stderr, "usage: %s %s\n", pname, usage_str); exit(1); } - diff --git a/radvd.h b/radvd.h index ab0d863b..e86aec5a 100644 --- a/radvd.h +++ b/radvd.h @@ -36,149 +36,148 @@ struct Clients; #define USER_HZ 100 struct Interface { - char Name[IFNAMSIZ]; /* interface name */ - - struct in6_addr if_addr; - unsigned int if_index; - - uint8_t init_racount; /* Initial RAs */ - - uint8_t if_hwaddr[HWADDR_MAX]; - int if_hwaddr_len; - int if_prefix_len; - int if_maxmtu; - - int cease_adv; - - struct timeval last_ra_time; - - int IgnoreIfMissing; - int AdvSendAdvert; - double MaxRtrAdvInterval; - double MinRtrAdvInterval; - double MinDelayBetweenRAs; - int AdvManagedFlag; - int AdvOtherConfigFlag; - uint32_t AdvLinkMTU; - uint32_t AdvReachableTime; - uint32_t AdvRetransTimer; - uint8_t AdvCurHopLimit; - int32_t AdvDefaultLifetime; /* XXX: really uint16_t but we need to use -1 */ - int AdvDefaultPreference; - int AdvSourceLLAddress; - int UnicastOnly; + char Name[IFNAMSIZ]; /* interface name */ + + struct in6_addr if_addr; + unsigned int if_index; + + uint8_t init_racount; /* Initial RAs */ + + uint8_t if_hwaddr[HWADDR_MAX]; + int if_hwaddr_len; + int if_prefix_len; + int if_maxmtu; + + int cease_adv; + + struct timeval last_ra_time; + + int IgnoreIfMissing; + int AdvSendAdvert; + double MaxRtrAdvInterval; + double MinRtrAdvInterval; + double MinDelayBetweenRAs; + int AdvManagedFlag; + int AdvOtherConfigFlag; + uint32_t AdvLinkMTU; + uint32_t AdvReachableTime; + uint32_t AdvRetransTimer; + uint8_t AdvCurHopLimit; + int32_t AdvDefaultLifetime; /* XXX: really uint16_t but we need to use -1 */ + int AdvDefaultPreference; + int AdvSourceLLAddress; + int UnicastOnly; /* Mobile IPv6 extensions */ - int AdvIntervalOpt; - int AdvHomeAgentInfo; - int AdvHomeAgentFlag; - uint16_t HomeAgentPreference; - int32_t HomeAgentLifetime; /* XXX: really uint16_t but we need to use -1 */ + int AdvIntervalOpt; + int AdvHomeAgentInfo; + int AdvHomeAgentFlag; + uint16_t HomeAgentPreference; + int32_t HomeAgentLifetime; /* XXX: really uint16_t but we need to use -1 */ /* NEMO extensions */ - int AdvMobRtrSupportFlag; + int AdvMobRtrSupportFlag; - struct AdvPrefix *AdvPrefixList; - struct AdvRoute *AdvRouteList; - struct AdvRDNSS *AdvRDNSSList; - struct AdvDNSSL *AdvDNSSLList; - struct Clients *ClientList; - struct timeval last_multicast; - struct timeval next_multicast; + struct AdvPrefix *AdvPrefixList; + struct AdvRoute *AdvRouteList; + struct AdvRDNSS *AdvRDNSSList; + struct AdvDNSSL *AdvDNSSLList; + struct Clients *ClientList; + struct timeval last_multicast; + struct timeval next_multicast; /* Info whether this interface has failed in the past (and may need to be reinitialized) */ - int HasFailed; + int HasFailed; - struct Interface *next; + struct Interface *next; }; struct Clients { - struct in6_addr Address; - struct Clients *next; + struct in6_addr Address; + struct Clients *next; }; struct AdvPrefix { - struct in6_addr Prefix; - uint8_t PrefixLen; + struct in6_addr Prefix; + uint8_t PrefixLen; - int AdvOnLinkFlag; - int AdvAutonomousFlag; - uint32_t AdvValidLifetime; - uint32_t AdvPreferredLifetime; - int DeprecatePrefixFlag; - int DecrementLifetimesFlag; + int AdvOnLinkFlag; + int AdvAutonomousFlag; + uint32_t AdvValidLifetime; + uint32_t AdvPreferredLifetime; + int DeprecatePrefixFlag; + int DecrementLifetimesFlag; - uint32_t curr_validlft; - uint32_t curr_preferredlft; + uint32_t curr_validlft; + uint32_t curr_preferredlft; /* Mobile IPv6 extensions */ - int AdvRouterAddr; + int AdvRouterAddr; /* 6to4 etc. extensions */ - char if6to4[IFNAMSIZ]; - int enabled; - int AutoSelected; + char if6to4[IFNAMSIZ]; + int enabled; + int AutoSelected; /* Select prefixes from this interface. */ - char if6[IFNAMSIZ]; + char if6[IFNAMSIZ]; - struct AdvPrefix *next; + struct AdvPrefix *next; }; /* More-Specific Routes extensions */ struct AdvRoute { - struct in6_addr Prefix; - uint8_t PrefixLen; + struct in6_addr Prefix; + uint8_t PrefixLen; - int AdvRoutePreference; - uint32_t AdvRouteLifetime; - int RemoveRouteFlag; + int AdvRoutePreference; + uint32_t AdvRouteLifetime; + int RemoveRouteFlag; - struct AdvRoute *next; + struct AdvRoute *next; }; /* Options for DNS configuration */ struct AdvRDNSS { - int AdvRDNSSNumber; - uint32_t AdvRDNSSLifetime; - int FlushRDNSSFlag; - struct in6_addr AdvRDNSSAddr1; - struct in6_addr AdvRDNSSAddr2; - struct in6_addr AdvRDNSSAddr3; - - struct AdvRDNSS *next; + int AdvRDNSSNumber; + uint32_t AdvRDNSSLifetime; + int FlushRDNSSFlag; + struct in6_addr AdvRDNSSAddr1; + struct in6_addr AdvRDNSSAddr2; + struct in6_addr AdvRDNSSAddr3; + + struct AdvRDNSS *next; }; struct AdvDNSSL { - uint32_t AdvDNSSLLifetime; + uint32_t AdvDNSSLLifetime; - int AdvDNSSLNumber; - int FlushDNSSLFlag; - char **AdvDNSSLSuffixes; + int AdvDNSSLNumber; + int FlushDNSSLFlag; + char **AdvDNSSLSuffixes; - struct AdvDNSSL *next; + struct AdvDNSSL *next; }; /* Mobile IPv6 extensions */ struct AdvInterval { - uint8_t type; - uint8_t length; - uint16_t reserved; - uint32_t adv_ival; + uint8_t type; + uint8_t length; + uint16_t reserved; + uint32_t adv_ival; }; struct HomeAgentInfo { - uint8_t type; - uint8_t length; - uint16_t flags_reserved; - uint16_t preference; - uint16_t lifetime; + uint8_t type; + uint8_t length; + uint16_t flags_reserved; + uint16_t preference; + uint16_t lifetime; }; - /* gram.y */ int yyparse(void); @@ -193,8 +192,8 @@ void reset_prefix_lifetimes(void); /* timer.c */ struct timeval next_timeval(double next); int timevaldiff(struct timeval const *a, struct timeval const *b); -int next_time_msec(struct Interface const * iface); -int expired(struct Interface const * iface); +int next_time_msec(struct Interface const *iface); +int expired(struct Interface const *iface); /* device.c */ int update_device_info(struct Interface *); @@ -223,16 +222,10 @@ int open_icmpv6_socket(void); /* send.c */ int send_ra(struct Interface *iface, struct in6_addr *dest); int send_ra_forall(struct Interface *iface, struct in6_addr *dest); -int really_send( - struct in6_addr const *dest, - unsigned int if_index, - struct in6_addr if_addr, - unsigned char * buff, - size_t len); +int really_send(struct in6_addr const *dest, unsigned int if_index, struct in6_addr if_addr, unsigned char *buff, size_t len); /* process.c */ -void process(struct Interface *, unsigned char *, int, - struct sockaddr_in6 *, struct in6_pktinfo *, int); +void process(struct Interface *, unsigned char *, int, struct sockaddr_in6 *, struct in6_pktinfo *, int); /* recv.c */ int recv_rs_ra(unsigned char *, struct sockaddr_in6 *, struct in6_pktinfo **, int *); @@ -266,21 +259,21 @@ int privsep_interface_retranstimer(const char *iface, uint32_t rettimer); * these are placed here because they're needed in all of socket.c, recv.c and send.c */ #ifdef __linux__ -# if defined IPV6_RECVHOPLIMIT || defined IPV6_RECVPKTINFO -# include -# if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) -# if defined IPV6_RECVHOPLIMIT && defined IPV6_2292HOPLIMIT -# undef IPV6_RECVHOPLIMIT -# define IPV6_RECVHOPLIMIT IPV6_2292HOPLIMIT -# endif -# if defined IPV6_RECVPKTINFO && defined IPV6_2292PKTINFO -# undef IPV6_RECVPKTINFO -# undef IPV6_PKTINFO -# define IPV6_RECVPKTINFO IPV6_2292PKTINFO -# define IPV6_PKTINFO IPV6_2292PKTINFO -# endif -# endif -# endif +#if defined IPV6_RECVHOPLIMIT || defined IPV6_RECVPKTINFO +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) +#if defined IPV6_RECVHOPLIMIT && defined IPV6_2292HOPLIMIT +#undef IPV6_RECVHOPLIMIT +#define IPV6_RECVHOPLIMIT IPV6_2292HOPLIMIT +#endif +#if defined IPV6_RECVPKTINFO && defined IPV6_2292PKTINFO +#undef IPV6_RECVPKTINFO +#undef IPV6_PKTINFO +#define IPV6_RECVPKTINFO IPV6_2292PKTINFO +#define IPV6_PKTINFO IPV6_2292PKTINFO +#endif +#endif +#endif #endif #endif diff --git a/radvdump.c b/radvdump.c index 22a0d04b..9c2cc212 100644 --- a/radvdump.c +++ b/radvdump.c @@ -38,19 +38,18 @@ void usage(void); void print_ff(unsigned char *, int, struct sockaddr_in6 *, int, unsigned int, int); void print_preferences(int); -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { unsigned char msg[MSG_SIZE_RECV]; int c, len, hoplimit; int edefs = 0; struct sockaddr_in6 rcv_addr; - struct in6_pktinfo *pkt_info = NULL; + struct in6_pktinfo *pkt_info = NULL; #ifdef HAVE_GETOPT_LONG int opt_idx; #endif - pname = ((pname=strrchr(argv[0],'/')) != NULL)?pname+1:argv[0]; + pname = ((pname = strrchr(argv[0], '/')) != NULL) ? pname + 1 : argv[0]; /* parse args */ #ifdef HAVE_GETOPT_LONG @@ -75,8 +74,7 @@ main(int argc, char *argv[]) usage(); #ifdef HAVE_GETOPT_LONG case ':': - fprintf(stderr, "%s: option %s: parameter expected\n", pname, - prog_opt[opt_idx].name); + fprintf(stderr, "%s: option %s: parameter expected\n", pname, prog_opt[opt_idx].name); exit(1); #endif case '?': @@ -96,31 +94,25 @@ main(int argc, char *argv[]) exit(1); } - for(;;) - { - len = recv_rs_ra(msg, &rcv_addr, &pkt_info, &hoplimit); - if (len > 0) - { + for (;;) { + len = recv_rs_ra(msg, &rcv_addr, &pkt_info, &hoplimit); + if (len > 0) { struct icmp6_hdr *icmph; /* * can this happen? */ - if (len < sizeof(struct icmp6_hdr)) - { - flog(LOG_WARNING, "received icmpv6 packet with invalid length: %d", - len); + if (len < sizeof(struct icmp6_hdr)) { + flog(LOG_WARNING, "received icmpv6 packet with invalid length: %d", len); exit(1); } - icmph = (struct icmp6_hdr *) msg; + icmph = (struct icmp6_hdr *)msg; - if (icmph->icmp6_type != ND_ROUTER_SOLICIT && - icmph->icmp6_type != ND_ROUTER_ADVERT) - { + if (icmph->icmp6_type != ND_ROUTER_SOLICIT && icmph->icmp6_type != ND_ROUTER_ADVERT) { /* - * We just want to listen to RSs and RAs + * We just want to listen to RSs and RAs */ flog(LOG_ERR, "icmpv6 filter failed"); @@ -129,30 +121,23 @@ main(int argc, char *argv[]) dlog(LOG_DEBUG, 4, "receiver if_index: %u", pkt_info->ipi6_ifindex); - if (icmph->icmp6_type == ND_ROUTER_SOLICIT) - { + if (icmph->icmp6_type == ND_ROUTER_SOLICIT) { /* not yet */ - } - else if (icmph->icmp6_type == ND_ROUTER_ADVERT) + } else if (icmph->icmp6_type == ND_ROUTER_ADVERT) print_ff(msg, len, &rcv_addr, hoplimit, (unsigned int)pkt_info->ipi6_ifindex, edefs); - } - else if (len == 0) - { - flog(LOG_ERR, "received zero lenght packet"); - exit(1); - } - else - { + } else if (len == 0) { + flog(LOG_ERR, "received zero lenght packet"); + exit(1); + } else { flog(LOG_ERR, "recv_rs_ra: %s", strerror(errno)); exit(1); - } - } + } + } exit(0); } -void -print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, unsigned int if_index, int edefs) +void print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, unsigned int if_index, int edefs) { /* XXX: hoplimit not being used for anything here.. */ struct nd_router_advert *radvert; @@ -170,39 +155,36 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u printf("\t# Note: {Min,Max}RtrAdvInterval cannot be obtained with radvdump\n"); - radvert = (struct nd_router_advert *) msg; + radvert = (struct nd_router_advert *)msg; if (!edefs || DFLT_AdvManagedFlag != (ND_RA_FLAG_MANAGED == (radvert->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED))) - printf("\tAdvManagedFlag %s;\n", - (radvert->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED)?"on":"off"); + printf("\tAdvManagedFlag %s;\n", (radvert->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) ? "on" : "off"); if (!edefs || DFLT_AdvOtherConfigFlag != (ND_RA_FLAG_OTHER == (radvert->nd_ra_flags_reserved & ND_RA_FLAG_OTHER))) - printf("\tAdvOtherConfigFlag %s;\n", - (radvert->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)?"on":"off"); + printf("\tAdvOtherConfigFlag %s;\n", (radvert->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) ? "on" : "off"); if (!edefs || DFLT_AdvReachableTime != ntohl(radvert->nd_ra_reachable)) - printf("\tAdvReachableTime %u;\n", ntohl(radvert->nd_ra_reachable)); + printf("\tAdvReachableTime %u;\n", ntohl(radvert->nd_ra_reachable)); if (!edefs || DFLT_AdvRetransTimer != ntohl(radvert->nd_ra_retransmit)) - printf("\tAdvRetransTimer %u;\n", ntohl(radvert->nd_ra_retransmit)); + printf("\tAdvRetransTimer %u;\n", ntohl(radvert->nd_ra_retransmit)); if (!edefs || DFLT_AdvCurHopLimit != radvert->nd_ra_curhoplimit) - printf("\tAdvCurHopLimit %u;\n", radvert->nd_ra_curhoplimit); + printf("\tAdvCurHopLimit %u;\n", radvert->nd_ra_curhoplimit); - if (!edefs || (3*DFLT_MaxRtrAdvInterval) != ntohs(radvert->nd_ra_router_lifetime)) - printf("\tAdvDefaultLifetime %hu;\n", ntohs(radvert->nd_ra_router_lifetime)); + if (!edefs || (3 * DFLT_MaxRtrAdvInterval) != ntohs(radvert->nd_ra_router_lifetime)) + printf("\tAdvDefaultLifetime %hu;\n", ntohs(radvert->nd_ra_router_lifetime)); /* Mobile IPv6 ext */ if (!edefs || DFLT_AdvHomeAgentFlag != (ND_RA_FLAG_HOME_AGENT == (radvert->nd_ra_flags_reserved & ND_RA_FLAG_HOME_AGENT))) - printf("\tAdvHomeAgentFlag %s;\n", - (radvert->nd_ra_flags_reserved & ND_RA_FLAG_HOME_AGENT)?"on":"off"); + printf("\tAdvHomeAgentFlag %s;\n", (radvert->nd_ra_flags_reserved & ND_RA_FLAG_HOME_AGENT) ? "on" : "off"); - /* Route Preferences and more specific routes */ - /* XXX two middlemost bits from 8 bit field */ + /* Route Preferences and more specific routes */ + /* XXX two middlemost bits from 8 bit field */ if (!edefs || (((radvert->nd_ra_flags_reserved & 0x18) >> 3) & 0xff) != DFLT_AdvDefaultPreference) { - printf("\tAdvDefaultPreference "); - print_preferences(((radvert->nd_ra_flags_reserved & 0x18) >> 3) & 0xff); - printf(";\n"); + printf("\tAdvDefaultPreference "); + print_preferences(((radvert->nd_ra_flags_reserved & 0x18) >> 3) & 0xff); + printf(";\n"); } len -= sizeof(struct nd_router_advert); @@ -210,56 +192,47 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u if (len == 0) return; - opt_str = (uint8_t *)(msg + sizeof(struct nd_router_advert)); + opt_str = (uint8_t *) (msg + sizeof(struct nd_router_advert)); - while (len > 0) - { + while (len > 0) { int optlen; struct nd_opt_mtu *mtu; struct HomeAgentInfo *ha_info; - if (len < 2) - { - flog(LOG_ERR, "trailing garbage in RA from %s", - addr_str); + if (len < 2) { + flog(LOG_ERR, "trailing garbage in RA from %s", addr_str); break; } optlen = (opt_str[1] << 3); - if (optlen == 0) - { + if (optlen == 0) { flog(LOG_ERR, "zero length option in RA"); break; - } - else if (optlen > len) - { - flog(LOG_ERR, "option length greater than total" - " length in RA (type %d, optlen %d, len %d)", - (int)*opt_str, optlen, len); + } else if (optlen > len) { + flog(LOG_ERR, "option length greater than total" " length in RA (type %d, optlen %d, len %d)", (int)*opt_str, optlen, len); break; } - switch (*opt_str) - { + switch (*opt_str) { case ND_OPT_MTU: mtu = (struct nd_opt_mtu *)opt_str; if (!edefs || DFLT_AdvLinkMTU != ntohl(mtu->nd_opt_mtu_mtu)) - printf("\tAdvLinkMTU %u;\n", ntohl(mtu->nd_opt_mtu_mtu)); + printf("\tAdvLinkMTU %u;\n", ntohl(mtu->nd_opt_mtu_mtu)); break; case ND_OPT_SOURCE_LINKADDR: /* XXX: !DFLT depends on current DFLT_ value */ if (!edefs || !DFLT_AdvSourceLLAddress) - printf("\tAdvSourceLLAddress on;\n"); + printf("\tAdvSourceLLAddress on;\n"); break; - /* Mobile IPv6 ext */ + /* Mobile IPv6 ext */ case ND_OPT_RTR_ADV_INTERVAL: /* XXX: !DFLT depends on current DFLT_ value */ if (!edefs || !DFLT_AdvIntervalOpt) - printf("\tAdvIntervalOpt on;\n"); + printf("\tAdvIntervalOpt on;\n"); break; - /* Mobile IPv6 ext */ + /* Mobile IPv6 ext */ case ND_OPT_HOME_AGENT_INFO: ha_info = (struct HomeAgentInfo *)opt_str; @@ -269,13 +242,13 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u /* NEMO ext */ if (!edefs || DFLT_AdvMobRtrSupportFlag != (ha_info->flags_reserved & ND_OPT_HAI_FLAG_SUPPORT_MR)) - printf("\tAdvMobRtrSupportFlag %s;\n", (ha_info->flags_reserved & ND_OPT_HAI_FLAG_SUPPORT_MR)?"on":"off"); + printf("\tAdvMobRtrSupportFlag %s;\n", (ha_info->flags_reserved & ND_OPT_HAI_FLAG_SUPPORT_MR) ? "on" : "off"); if (!edefs || DFLT_HomeAgentPreference != ntohs(ha_info->preference)) - printf("\tHomeAgentPreference %hu;\n", ntohs(ha_info->preference)); + printf("\tHomeAgentPreference %hu;\n", ntohs(ha_info->preference)); /* Hum.. */ - if (!edefs || (3*DFLT_MaxRtrAdvInterval) != ntohs(ha_info->lifetime)) - printf("\tHomeAgentLifetime %hu;\n", ntohs(ha_info->lifetime)); + if (!edefs || (3 * DFLT_MaxRtrAdvInterval) != ntohs(ha_info->lifetime)) + printf("\tHomeAgentLifetime %hu;\n", ntohs(ha_info->lifetime)); break; case ND_OPT_TARGET_LINKADDR: case ND_OPT_REDIRECTED_HEADER: @@ -290,8 +263,7 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u case ND_OPT_DNSSL_INFORMATION: break; default: - dlog(LOG_DEBUG, 1, "unknown option %d in RA", - (int)*opt_str); + dlog(LOG_DEBUG, 1, "unknown option %d in RA", (int)*opt_str); break; } @@ -304,10 +276,9 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u if (orig_len == 0) return; - opt_str = (uint8_t *)(msg + sizeof(struct nd_router_advert)); + opt_str = (uint8_t *) (msg + sizeof(struct nd_router_advert)); - while (orig_len > 0) - { + while (orig_len > 0) { int optlen; struct nd_opt_prefix_info *pinfo; struct nd_opt_route_info_local *rinfo; @@ -317,80 +288,62 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u char suffix[256]; int offset, label_len; - if (orig_len < 2) - { - flog(LOG_ERR, "trailing garbage in RA from %s", - addr_str); + if (orig_len < 2) { + flog(LOG_ERR, "trailing garbage in RA from %s", addr_str); break; } optlen = (opt_str[1] << 3); - if (optlen == 0) - { + if (optlen == 0) { flog(LOG_ERR, "zero length option in RA"); break; - } - else if (optlen > orig_len) - { - flog(LOG_ERR, "option length greater than total" - " length in RA (type %d, optlen %d, len %d)", - (int)*opt_str, optlen, orig_len); + } else if (optlen > orig_len) { + flog(LOG_ERR, "option length greater than total" " length in RA (type %d, optlen %d, len %d)", (int)*opt_str, optlen, orig_len); break; } - switch (*opt_str) - { + switch (*opt_str) { case ND_OPT_PREFIX_INFORMATION: - pinfo = (struct nd_opt_prefix_info *) opt_str; + pinfo = (struct nd_opt_prefix_info *)opt_str; print_addr(&pinfo->nd_opt_pi_prefix, prefix_str); printf("\n\tprefix %s/%d\n\t{\n", prefix_str, pinfo->nd_opt_pi_prefix_len); - if (ntohl(pinfo->nd_opt_pi_valid_time) == 0xffffffff) - { + if (ntohl(pinfo->nd_opt_pi_valid_time) == 0xffffffff) { if (!edefs || DFLT_AdvValidLifetime != 0xffffffff) - printf("\t\tAdvValidLifetime infinity; # (0xffffffff)\n"); - } - else - { + printf("\t\tAdvValidLifetime infinity; # (0xffffffff)\n"); + } else { if (!edefs || DFLT_AdvValidLifetime != ntohl(pinfo->nd_opt_pi_valid_time)) - printf("\t\tAdvValidLifetime %u;\n", ntohl(pinfo->nd_opt_pi_valid_time)); + printf("\t\tAdvValidLifetime %u;\n", ntohl(pinfo->nd_opt_pi_valid_time)); } - if (ntohl(pinfo->nd_opt_pi_preferred_time) == 0xffffffff) - { + if (ntohl(pinfo->nd_opt_pi_preferred_time) == 0xffffffff) { if (!edefs || DFLT_AdvPreferredLifetime != 0xffffffff) - printf("\t\tAdvPreferredLifetime infinity; # (0xffffffff)\n"); - } - else - { + printf("\t\tAdvPreferredLifetime infinity; # (0xffffffff)\n"); + } else { if (!edefs || DFLT_AdvPreferredLifetime != ntohl(pinfo->nd_opt_pi_preferred_time)) - printf("\t\tAdvPreferredLifetime %u;\n", ntohl(pinfo->nd_opt_pi_preferred_time)); + printf("\t\tAdvPreferredLifetime %u;\n", ntohl(pinfo->nd_opt_pi_preferred_time)); } if (!edefs || DFLT_AdvOnLinkFlag != (ND_OPT_PI_FLAG_ONLINK == (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK))) - printf("\t\tAdvOnLink %s;\n", - (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)?"on":"off"); + printf("\t\tAdvOnLink %s;\n", (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK) ? "on" : "off"); if (!edefs || DFLT_AdvAutonomousFlag != (ND_OPT_PI_FLAG_AUTO == (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO))) - printf("\t\tAdvAutonomous %s;\n", - (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)?"on":"off"); + printf("\t\tAdvAutonomous %s;\n", (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO) ? "on" : "off"); /* Mobile IPv6 ext */ if (!edefs || DFLT_AdvRouterAddr != (ND_OPT_PI_FLAG_RADDR == (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_RADDR))) - printf("\t\tAdvRouterAddr %s;\n", - (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_RADDR)?"on":"off"); + printf("\t\tAdvRouterAddr %s;\n", (pinfo->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_RADDR) ? "on" : "off"); printf("\t}; # End of prefix definition\n\n"); break; case ND_OPT_ROUTE_INFORMATION: - rinfo = (struct nd_opt_route_info_local *) opt_str; + rinfo = (struct nd_opt_route_info_local *)opt_str; if (optlen == 8) { printf("\n\troute ::/0\n\t{\n"); - } - else { + } else { struct in6_addr addr; memset(&addr, 0, sizeof(addr)); memcpy(&addr, &rinfo->nd_opt_ri_prefix, 8); @@ -413,7 +366,7 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u printf("\t}; # End of route definition\n\n"); break; case ND_OPT_RDNSS_INFORMATION: - rdnss_info = (struct nd_opt_rdnss_info_local *) opt_str; + rdnss_info = (struct nd_opt_rdnss_info_local *)opt_str; printf("\n\tRDNSS"); @@ -439,12 +392,12 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u printf("\t}; # End of RDNSS definition\n\n"); break; case ND_OPT_DNSSL_INFORMATION: - dnssl_info = (struct nd_opt_dnssl_info_local *) opt_str; + dnssl_info = (struct nd_opt_dnssl_info_local *)opt_str; printf("\n\tDNSSL"); suffix[0] = '\0'; - for (offset = 0;offset < (dnssl_info->nd_opt_dnssli_len-1)*8;) { + for (offset = 0; offset < (dnssl_info->nd_opt_dnssli_len - 1) * 8;) { label_len = dnssl_info->nd_opt_dnssli_suffixes[offset++]; if (label_len == 0) { @@ -462,14 +415,13 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u } if ((sizeof(suffix) - strlen(suffix)) < (label_len + 2)) { - flog(LOG_ERR, "oversized suffix in DNSSL option from %s", - addr_str); + flog(LOG_ERR, "oversized suffix in DNSSL option from %s", addr_str); break; } if (suffix[0] != '\0') strcat(suffix, "."); - strncat(suffix, (char*)&dnssl_info->nd_opt_dnssli_suffixes[offset], label_len); + strncat(suffix, (char *)&dnssl_info->nd_opt_dnssli_suffixes[offset], label_len); offset += label_len; } @@ -494,37 +446,33 @@ print_ff(unsigned char *msg, int len, struct sockaddr_in6 *addr, int hoplimit, u fflush(stdout); } -void -print_preferences(int p) +void print_preferences(int p) { switch (p) { - case 0: - printf("medium"); - break; - case 1: - printf("high"); - break; - case 2: - /* reserved, ignore */ - break; - case 3: - printf("low"); - break; + case 0: + printf("medium"); + break; + case 1: + printf("high"); + break; + case 2: + /* reserved, ignore */ + break; + case 3: + printf("low"); + break; } } -void -version(void) +void version(void) { - fprintf(stderr,"Version: %s\n\n", VERSION); - fprintf(stderr,"Please send bug reports and suggestions to %s\n", - CONTACT_EMAIL); + fprintf(stderr, "Version: %s\n\n", VERSION); + fprintf(stderr, "Please send bug reports and suggestions to %s\n", CONTACT_EMAIL); exit(1); } -void -usage(void) +void usage(void) { - fprintf(stderr,"usage: %s %s\n", pname, usage_str); + fprintf(stderr, "usage: %s %s\n", pname, usage_str); exit(1); } diff --git a/recv.c b/recv.c index aa994d11..7978e5b5 100644 --- a/recv.c +++ b/recv.c @@ -17,9 +17,7 @@ #include "includes.h" #include "radvd.h" -int -recv_rs_ra(unsigned char *msg, struct sockaddr_in6 *addr, - struct in6_pktinfo **pkt_info, int *hoplimit) +int recv_rs_ra(unsigned char *msg, struct sockaddr_in6 *addr, struct in6_pktinfo **pkt_info, int *hoplimit) { struct msghdr mhdr; struct cmsghdr *cmsg; @@ -29,21 +27,18 @@ recv_rs_ra(unsigned char *msg, struct sockaddr_in6 *addr, int len; fd_set rfds; - if( ! chdr ) - { - chdrlen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + - CMSG_SPACE(sizeof(int)); + if (!chdr) { + chdrlen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)); if ((chdr = malloc(chdrlen)) == NULL) { flog(LOG_ERR, "recv_rs_ra: malloc: %s", strerror(errno)); return -1; } } - FD_ZERO( &rfds ); - FD_SET( sock, &rfds ); + FD_ZERO(&rfds); + FD_SET(sock, &rfds); - if( select( sock+1, &rfds, NULL, NULL, NULL ) < 0 ) - { + if (select(sock + 1, &rfds, NULL, NULL, NULL) < 0) { if (errno != EINTR) flog(LOG_ERR, "select: %s", strerror(errno)); @@ -54,7 +49,7 @@ recv_rs_ra(unsigned char *msg, struct sockaddr_in6 *addr, iov.iov_base = (caddr_t) msg; memset(&mhdr, 0, sizeof(mhdr)); - mhdr.msg_name = (caddr_t)addr; + mhdr.msg_name = (caddr_t) addr; mhdr.msg_namelen = sizeof(*addr); mhdr.msg_iov = &iov; mhdr.msg_iovlen = 1; @@ -63,8 +58,7 @@ recv_rs_ra(unsigned char *msg, struct sockaddr_in6 *addr, len = recvmsg(sock, &mhdr, 0); - if (len < 0) - { + if (len < 0) { if (errno != EINTR) flog(LOG_ERR, "recvmsg: %s", strerror(errno)); @@ -73,43 +67,31 @@ recv_rs_ra(unsigned char *msg, struct sockaddr_in6 *addr, *hoplimit = 255; - for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg != NULL; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) - { - if (cmsg->cmsg_level != IPPROTO_IPV6) - continue; + for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg != NULL; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) { + if (cmsg->cmsg_level != IPPROTO_IPV6) + continue; - switch(cmsg->cmsg_type) - { + switch (cmsg->cmsg_type) { #ifdef IPV6_HOPLIMIT - case IPV6_HOPLIMIT: - if ((cmsg->cmsg_len == CMSG_LEN(sizeof(int))) && - (*(int *)CMSG_DATA(cmsg) >= 0) && - (*(int *)CMSG_DATA(cmsg) < 256)) - { - *hoplimit = *(int *)CMSG_DATA(cmsg); - } - else - { - flog(LOG_ERR, "received a bogus IPV6_HOPLIMIT from the kernel! len=%d, data=%d", - cmsg->cmsg_len, *(int *)CMSG_DATA(cmsg)); - return (-1); - } - break; -#endif /* IPV6_HOPLIMIT */ - case IPV6_PKTINFO: - if ((cmsg->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo))) && - ((struct in6_pktinfo *)CMSG_DATA(cmsg))->ipi6_ifindex) - { - *pkt_info = (struct in6_pktinfo *)CMSG_DATA(cmsg); - } - else - { - flog(LOG_ERR, "received a bogus IPV6_PKTINFO from the kernel! len=%d, index=%d", - cmsg->cmsg_len, ((struct in6_pktinfo *)CMSG_DATA(cmsg))->ipi6_ifindex); - return (-1); - } - break; - } + case IPV6_HOPLIMIT: + if ((cmsg->cmsg_len == CMSG_LEN(sizeof(int))) && (*(int *)CMSG_DATA(cmsg) >= 0) && (*(int *)CMSG_DATA(cmsg) < 256)) { + *hoplimit = *(int *)CMSG_DATA(cmsg); + } else { + flog(LOG_ERR, "received a bogus IPV6_HOPLIMIT from the kernel! len=%d, data=%d", cmsg->cmsg_len, *(int *)CMSG_DATA(cmsg)); + return (-1); + } + break; +#endif /* IPV6_HOPLIMIT */ + case IPV6_PKTINFO: + if ((cmsg->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo))) && ((struct in6_pktinfo *)CMSG_DATA(cmsg))->ipi6_ifindex) { + *pkt_info = (struct in6_pktinfo *)CMSG_DATA(cmsg); + } else { + flog(LOG_ERR, "received a bogus IPV6_PKTINFO from the kernel! len=%d, index=%d", + cmsg->cmsg_len, ((struct in6_pktinfo *)CMSG_DATA(cmsg))->ipi6_ifindex); + return (-1); + } + break; + } } dlog(LOG_DEBUG, 4, "recvmsg len=%d", len); diff --git a/send.c b/send.c index fc28117f..0d7ed5be 100644 --- a/send.c +++ b/send.c @@ -25,8 +25,7 @@ * address only, but only if it was configured. * */ -int -send_ra_forall(struct Interface *iface, struct in6_addr *dest) +int send_ra_forall(struct Interface *iface, struct in6_addr *dest) { struct Clients *current; @@ -35,14 +34,13 @@ send_ra_forall(struct Interface *iface, struct in6_addr *dest) return send_ra(iface, dest); /* If clients are configured, send the advertisement to all of them via unicast */ - for (current = iface->ClientList; current; current = current->next) - { + for (current = iface->ClientList; current; current = current->next) { char address_text[INET6_ADDRSTRLEN]; memset(address_text, 0, sizeof(address_text)); if (get_debuglevel() >= 5) inet_ntop(AF_INET6, ¤t->Address, address_text, INET6_ADDRSTRLEN); - /* If a non-authorized client sent a solicitation, ignore it (logging later) */ + /* If a non-authorized client sent a solicitation, ignore it (logging later) */ if (dest != NULL && memcmp(dest, ¤t->Address, sizeof(struct in6_addr)) != 0) continue; dlog(LOG_DEBUG, 5, "Sending RA to %s", address_text); @@ -55,7 +53,7 @@ send_ra_forall(struct Interface *iface, struct in6_addr *dest) if (dest == NULL) return 0; - /* If we refused a client's solicitation, log it if debugging is high enough */ + /* If we refused a client's solicitation, log it if debugging is high enough */ char address_text[INET6_ADDRSTRLEN]; memset(address_text, 0, sizeof(address_text)); if (get_debuglevel() >= 5) @@ -65,19 +63,16 @@ send_ra_forall(struct Interface *iface, struct in6_addr *dest) return 0; } -static void -send_ra_inc_len(size_t *len, int add) +static void send_ra_inc_len(size_t * len, int add) { *len += add; - if(*len >= MSG_SIZE_SEND) - { + if (*len >= MSG_SIZE_SEND) { flog(LOG_ERR, "Too many prefixes, routes, rdnss or dnssl to fit in buffer. Exiting."); exit(1); } } -static time_t -time_diff_secs(const struct timeval *time_x, const struct timeval *time_y) +static time_t time_diff_secs(const struct timeval *time_x, const struct timeval *time_y) { time_t secs_diff; @@ -86,15 +81,14 @@ time_diff_secs(const struct timeval *time_x, const struct timeval *time_y) secs_diff++; return secs_diff; - + } -static void -decrement_lifetime(const time_t secs, uint32_t *lifetime) +static void decrement_lifetime(const time_t secs, uint32_t * lifetime) { if (*lifetime > secs) { - *lifetime -= secs; + *lifetime -= secs; } else { *lifetime = 0; } @@ -110,10 +104,9 @@ static void cease_adv_pfx_msg(const char *if_name, struct in6_addr *pfx, const i } -int -send_ra(struct Interface *iface, struct in6_addr *dest) +int send_ra(struct Interface *iface, struct in6_addr *dest) { - uint8_t all_hosts_addr[] = {0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; + uint8_t all_hosts_addr[] = { 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; struct nd_router_advert *radvert; struct AdvPrefix *prefix; struct AdvRoute *route; @@ -128,12 +121,11 @@ send_ra(struct Interface *iface, struct in6_addr *dest) size_t len = 0; ssize_t err; - update_device_info(iface); /* First we need to check that the interface hasn't been removed or deactivated */ - if(check_device(iface) < 0) { - if (iface->IgnoreIfMissing) /* a bit more quiet warning message.. */ + if (check_device(iface) < 0) { + if (iface->IgnoreIfMissing) /* a bit more quiet warning message.. */ dlog(LOG_DEBUG, 4, "interface %s does not exist, ignoring the interface", iface->Name); else { flog(LOG_WARNING, "interface %s does not exist, ignoring the interface", iface->Name); @@ -160,16 +152,14 @@ send_ra(struct Interface *iface, struct in6_addr *dest) if (!disableigmp6check && check_allrouters_membership(iface) < 0) flog(LOG_WARNING, "problem checking all-routers membership on %s", iface->Name); - if (!iface->AdvSendAdvert) - { + if (!iface->AdvSendAdvert) { dlog(LOG_DEBUG, 2, "AdvSendAdvert is off for %s", iface->Name); return 0; } dlog(LOG_DEBUG, 3, "sending RA on %s", iface->Name); - if (dest == NULL) - { + if (dest == NULL) { dest = (struct in6_addr *)all_hosts_addr; gettimeofday(&iface->last_multicast, NULL); } @@ -183,85 +173,73 @@ send_ra(struct Interface *iface, struct in6_addr *dest) iface->last_ra_time = time_now; memset(buff, 0, sizeof(buff)); - radvert = (struct nd_router_advert *) buff; + radvert = (struct nd_router_advert *)buff; send_ra_inc_len(&len, sizeof(struct nd_router_advert)); - radvert->nd_ra_type = ND_ROUTER_ADVERT; - radvert->nd_ra_code = 0; + radvert->nd_ra_type = ND_ROUTER_ADVERT; + radvert->nd_ra_code = 0; radvert->nd_ra_cksum = 0; - radvert->nd_ra_curhoplimit = iface->AdvCurHopLimit; - radvert->nd_ra_flags_reserved = - (iface->AdvManagedFlag)?ND_RA_FLAG_MANAGED:0; - radvert->nd_ra_flags_reserved |= - (iface->AdvOtherConfigFlag)?ND_RA_FLAG_OTHER:0; + radvert->nd_ra_curhoplimit = iface->AdvCurHopLimit; + radvert->nd_ra_flags_reserved = (iface->AdvManagedFlag) ? ND_RA_FLAG_MANAGED : 0; + radvert->nd_ra_flags_reserved |= (iface->AdvOtherConfigFlag) ? ND_RA_FLAG_OTHER : 0; /* Mobile IPv6 ext */ - radvert->nd_ra_flags_reserved |= - (iface->AdvHomeAgentFlag)?ND_RA_FLAG_HOME_AGENT:0; + radvert->nd_ra_flags_reserved |= (iface->AdvHomeAgentFlag) ? ND_RA_FLAG_HOME_AGENT : 0; if (iface->cease_adv) { radvert->nd_ra_router_lifetime = 0; } else { /* if forwarding is disabled, send zero router lifetime */ - radvert->nd_ra_router_lifetime = !check_ip6_forwarding() ? htons(iface->AdvDefaultLifetime) : 0; + radvert->nd_ra_router_lifetime = !check_ip6_forwarding()? htons(iface->AdvDefaultLifetime) : 0; } - radvert->nd_ra_flags_reserved |= - (iface->AdvDefaultPreference << ND_OPT_RI_PRF_SHIFT) & ND_OPT_RI_PRF_MASK; + radvert->nd_ra_flags_reserved |= (iface->AdvDefaultPreference << ND_OPT_RI_PRF_SHIFT) & ND_OPT_RI_PRF_MASK; - radvert->nd_ra_reachable = htonl(iface->AdvReachableTime); + radvert->nd_ra_reachable = htonl(iface->AdvReachableTime); radvert->nd_ra_retransmit = htonl(iface->AdvRetransTimer); prefix = iface->AdvPrefixList; /* - * add prefix options + * add prefix options */ - while(prefix) - { - if( prefix->enabled && (!prefix->DecrementLifetimesFlag || prefix->curr_preferredlft > 0) ) - { + while (prefix) { + if (prefix->enabled && (!prefix->DecrementLifetimesFlag || prefix->curr_preferredlft > 0)) { struct nd_opt_prefix_info *pinfo; - pinfo = (struct nd_opt_prefix_info *) (buff + len); + pinfo = (struct nd_opt_prefix_info *)(buff + len); send_ra_inc_len(&len, sizeof(*pinfo)); - pinfo->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION; - pinfo->nd_opt_pi_len = 4; - pinfo->nd_opt_pi_prefix_len = prefix->PrefixLen; + pinfo->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION; + pinfo->nd_opt_pi_len = 4; + pinfo->nd_opt_pi_prefix_len = prefix->PrefixLen; - pinfo->nd_opt_pi_flags_reserved = - (prefix->AdvOnLinkFlag)?ND_OPT_PI_FLAG_ONLINK:0; - pinfo->nd_opt_pi_flags_reserved |= - (prefix->AdvAutonomousFlag)?ND_OPT_PI_FLAG_AUTO:0; + pinfo->nd_opt_pi_flags_reserved = (prefix->AdvOnLinkFlag) ? ND_OPT_PI_FLAG_ONLINK : 0; + pinfo->nd_opt_pi_flags_reserved |= (prefix->AdvAutonomousFlag) ? ND_OPT_PI_FLAG_AUTO : 0; /* Mobile IPv6 ext */ - pinfo->nd_opt_pi_flags_reserved |= - (prefix->AdvRouterAddr)?ND_OPT_PI_FLAG_RADDR:0; + pinfo->nd_opt_pi_flags_reserved |= (prefix->AdvRouterAddr) ? ND_OPT_PI_FLAG_RADDR : 0; if (iface->cease_adv && prefix->DeprecatePrefixFlag) { /* RFC4862, 5.5.3, step e) */ - pinfo->nd_opt_pi_valid_time = htonl(MIN_AdvValidLifetime); + pinfo->nd_opt_pi_valid_time = htonl(MIN_AdvValidLifetime); pinfo->nd_opt_pi_preferred_time = 0; } else { if (prefix->DecrementLifetimesFlag) { - decrement_lifetime(secs_since_last_ra, - &prefix->curr_validlft); - - decrement_lifetime(secs_since_last_ra, - &prefix->curr_preferredlft); + decrement_lifetime(secs_since_last_ra, &prefix->curr_validlft); + + decrement_lifetime(secs_since_last_ra, &prefix->curr_preferredlft); if (prefix->curr_preferredlft == 0) cease_adv_pfx_msg(iface->Name, &prefix->Prefix, prefix->PrefixLen); } - pinfo->nd_opt_pi_valid_time = htonl(prefix->curr_validlft); + pinfo->nd_opt_pi_valid_time = htonl(prefix->curr_validlft); pinfo->nd_opt_pi_preferred_time = htonl(prefix->curr_preferredlft); } - pinfo->nd_opt_pi_reserved2 = 0; + pinfo->nd_opt_pi_reserved2 = 0; - memcpy(&pinfo->nd_opt_pi_prefix, &prefix->Prefix, - sizeof(struct in6_addr)); + memcpy(&pinfo->nd_opt_pi_prefix, &prefix->Prefix, sizeof(struct in6_addr)); print_addr(&prefix->Prefix, addr_str); dlog(LOG_DEBUG, 5, "adding prefix %s to advert for %s", addr_str, iface->Name); } @@ -272,32 +250,29 @@ send_ra(struct Interface *iface, struct in6_addr *dest) route = iface->AdvRouteList; /* - * add route options + * add route options */ - while(route) - { + while (route) { struct nd_opt_route_info_local *rinfo; - rinfo = (struct nd_opt_route_info_local *) (buff + len); + rinfo = (struct nd_opt_route_info_local *)(buff + len); send_ra_inc_len(&len, sizeof(*rinfo)); - rinfo->nd_opt_ri_type = ND_OPT_ROUTE_INFORMATION; + rinfo->nd_opt_ri_type = ND_OPT_ROUTE_INFORMATION; /* XXX: the prefixes are allowed to be sent in smaller chunks as well */ - rinfo->nd_opt_ri_len = 3; - rinfo->nd_opt_ri_prefix_len = route->PrefixLen; + rinfo->nd_opt_ri_len = 3; + rinfo->nd_opt_ri_prefix_len = route->PrefixLen; - rinfo->nd_opt_ri_flags_reserved = - (route->AdvRoutePreference << ND_OPT_RI_PRF_SHIFT) & ND_OPT_RI_PRF_MASK; + rinfo->nd_opt_ri_flags_reserved = (route->AdvRoutePreference << ND_OPT_RI_PRF_SHIFT) & ND_OPT_RI_PRF_MASK; if (iface->cease_adv && route->RemoveRouteFlag) { - rinfo->nd_opt_ri_lifetime = 0; + rinfo->nd_opt_ri_lifetime = 0; } else { - rinfo->nd_opt_ri_lifetime = htonl(route->AdvRouteLifetime); + rinfo->nd_opt_ri_lifetime = htonl(route->AdvRouteLifetime); } - memcpy(&rinfo->nd_opt_ri_prefix, &route->Prefix, - sizeof(struct in6_addr)); + memcpy(&rinfo->nd_opt_ri_prefix, &route->Prefix, sizeof(struct in6_addr)); route = route->next; } @@ -305,33 +280,29 @@ send_ra(struct Interface *iface, struct in6_addr *dest) rdnss = iface->AdvRDNSSList; /* - * add rdnss options + * add rdnss options */ - while(rdnss) - { + while (rdnss) { struct nd_opt_rdnss_info_local *rdnssinfo; - rdnssinfo = (struct nd_opt_rdnss_info_local *) (buff + len); + rdnssinfo = (struct nd_opt_rdnss_info_local *)(buff + len); - send_ra_inc_len(&len, sizeof(*rdnssinfo) - (3-rdnss->AdvRDNSSNumber)*sizeof(struct in6_addr)); + send_ra_inc_len(&len, sizeof(*rdnssinfo) - (3 - rdnss->AdvRDNSSNumber) * sizeof(struct in6_addr)); - rdnssinfo->nd_opt_rdnssi_type = ND_OPT_RDNSS_INFORMATION; - rdnssinfo->nd_opt_rdnssi_len = 1 + 2*rdnss->AdvRDNSSNumber; + rdnssinfo->nd_opt_rdnssi_type = ND_OPT_RDNSS_INFORMATION; + rdnssinfo->nd_opt_rdnssi_len = 1 + 2 * rdnss->AdvRDNSSNumber; rdnssinfo->nd_opt_rdnssi_pref_flag_reserved = 0; if (iface->cease_adv && rdnss->FlushRDNSSFlag) { - rdnssinfo->nd_opt_rdnssi_lifetime = 0; + rdnssinfo->nd_opt_rdnssi_lifetime = 0; } else { - rdnssinfo->nd_opt_rdnssi_lifetime = htonl(rdnss->AdvRDNSSLifetime); + rdnssinfo->nd_opt_rdnssi_lifetime = htonl(rdnss->AdvRDNSSLifetime); } - memcpy(&rdnssinfo->nd_opt_rdnssi_addr1, &rdnss->AdvRDNSSAddr1, - sizeof(struct in6_addr)); - memcpy(&rdnssinfo->nd_opt_rdnssi_addr2, &rdnss->AdvRDNSSAddr2, - sizeof(struct in6_addr)); - memcpy(&rdnssinfo->nd_opt_rdnssi_addr3, &rdnss->AdvRDNSSAddr3, - sizeof(struct in6_addr)); + memcpy(&rdnssinfo->nd_opt_rdnssi_addr1, &rdnss->AdvRDNSSAddr1, sizeof(struct in6_addr)); + memcpy(&rdnssinfo->nd_opt_rdnssi_addr2, &rdnss->AdvRDNSSAddr2, sizeof(struct in6_addr)); + memcpy(&rdnssinfo->nd_opt_rdnssi_addr3, &rdnss->AdvRDNSSAddr3, sizeof(struct in6_addr)); rdnss = rdnss->next; } @@ -339,30 +310,27 @@ send_ra(struct Interface *iface, struct in6_addr *dest) dnssl = iface->AdvDNSSLList; /* - * add dnssl options + * add dnssl options */ - while(dnssl) - { + while (dnssl) { struct nd_opt_dnssl_info_local *dnsslinfo; int const start_len = len; int i; - dnsslinfo = (struct nd_opt_dnssl_info_local *) (buff + len); + dnsslinfo = (struct nd_opt_dnssl_info_local *)(buff + len); - send_ra_inc_len(&len, sizeof(dnsslinfo->nd_opt_dnssli_type) + - sizeof(dnsslinfo->nd_opt_dnssli_len) + - sizeof(dnsslinfo->nd_opt_dnssli_reserved) + - sizeof(dnsslinfo->nd_opt_dnssli_lifetime) - ); + send_ra_inc_len(&len, sizeof(dnsslinfo->nd_opt_dnssli_type) + + sizeof(dnsslinfo->nd_opt_dnssli_len) + sizeof(dnsslinfo->nd_opt_dnssli_reserved) + sizeof(dnsslinfo->nd_opt_dnssli_lifetime) + ); - dnsslinfo->nd_opt_dnssli_type = ND_OPT_DNSSL_INFORMATION; - dnsslinfo->nd_opt_dnssli_reserved = 0; + dnsslinfo->nd_opt_dnssli_type = ND_OPT_DNSSL_INFORMATION; + dnsslinfo->nd_opt_dnssli_reserved = 0; if (iface->cease_adv && dnssl->FlushDNSSLFlag) { - dnsslinfo->nd_opt_dnssli_lifetime = 0; + dnsslinfo->nd_opt_dnssli_lifetime = 0; } else { - dnsslinfo->nd_opt_dnssli_lifetime = htonl(dnssl->AdvDNSSLLifetime); + dnsslinfo->nd_opt_dnssli_lifetime = htonl(dnssl->AdvDNSSLLifetime); } for (i = 0; i < dnssl->AdvDNSSLNumber; i++) { @@ -399,7 +367,7 @@ send_ra(struct Interface *iface, struct in6_addr *dest) dnsslinfo->nd_opt_dnssli_len = (len - start_len) / 8; - if ( (len - start_len) % 8 != 0 ) { + if ((len - start_len) % 8 != 0) { send_ra_inc_len(&len, 8 - (len - start_len) % 8); ++dnsslinfo->nd_opt_dnssli_len; } @@ -408,28 +376,27 @@ send_ra(struct Interface *iface, struct in6_addr *dest) } /* - * add MTU option + * add MTU option */ if (iface->AdvLinkMTU != 0) { struct nd_opt_mtu *mtu; - mtu = (struct nd_opt_mtu *) (buff + len); + mtu = (struct nd_opt_mtu *)(buff + len); send_ra_inc_len(&len, sizeof(*mtu)); - mtu->nd_opt_mtu_type = ND_OPT_MTU; - mtu->nd_opt_mtu_len = 1; + mtu->nd_opt_mtu_type = ND_OPT_MTU; + mtu->nd_opt_mtu_len = 1; mtu->nd_opt_mtu_reserved = 0; - mtu->nd_opt_mtu_mtu = htonl(iface->AdvLinkMTU); + mtu->nd_opt_mtu_mtu = htonl(iface->AdvLinkMTU); } /* * add Source Link-layer Address option */ - if (iface->AdvSourceLLAddress && iface->if_hwaddr_len > 0) - { + if (iface->AdvSourceLLAddress && iface->if_hwaddr_len > 0) { uint8_t *ucp; unsigned int i; @@ -437,8 +404,8 @@ send_ra(struct Interface *iface, struct in6_addr *dest) send_ra_inc_len(&len, 2 * sizeof(uint8_t)); - *ucp++ = ND_OPT_SOURCE_LINKADDR; - *ucp++ = (uint8_t) ((iface->if_hwaddr_len + 16 + 63) >> 6); + *ucp++ = ND_OPT_SOURCE_LINKADDR; + *ucp++ = (uint8_t) ((iface->if_hwaddr_len + 16 + 63) >> 6); i = (iface->if_hwaddr_len + 7) >> 3; @@ -454,22 +421,19 @@ send_ra(struct Interface *iface, struct in6_addr *dest) * movement detection of mobile nodes */ - if(iface->AdvIntervalOpt) - { + if (iface->AdvIntervalOpt) { struct AdvInterval a_ival; - uint32_t ival; - if(iface->MaxRtrAdvInterval < Cautious_MaxRtrAdvInterval){ - ival = ((iface->MaxRtrAdvInterval + - Cautious_MaxRtrAdvInterval_Leeway ) * 1000); - - } - else { - ival = (iface->MaxRtrAdvInterval * 1000); - } - a_ival.type = ND_OPT_RTR_ADV_INTERVAL; - a_ival.length = 1; - a_ival.reserved = 0; - a_ival.adv_ival = htonl(ival); + uint32_t ival; + if (iface->MaxRtrAdvInterval < Cautious_MaxRtrAdvInterval) { + ival = ((iface->MaxRtrAdvInterval + Cautious_MaxRtrAdvInterval_Leeway) * 1000); + + } else { + ival = (iface->MaxRtrAdvInterval * 1000); + } + a_ival.type = ND_OPT_RTR_ADV_INTERVAL; + a_ival.length = 1; + a_ival.reserved = 0; + a_ival.adv_ival = htonl(ival); buff_dest = len; send_ra_inc_len(&len, sizeof(a_ival)); @@ -481,18 +445,14 @@ send_ra(struct Interface *iface, struct in6_addr *dest) * Dynamic Home Agent Address Discovery */ - if(iface->AdvHomeAgentInfo && - (iface->AdvMobRtrSupportFlag || iface->HomeAgentPreference != 0 || - iface->HomeAgentLifetime != iface->AdvDefaultLifetime)) - + if (iface->AdvHomeAgentInfo && (iface->AdvMobRtrSupportFlag || iface->HomeAgentPreference != 0 || iface->HomeAgentLifetime != iface->AdvDefaultLifetime)) { struct HomeAgentInfo ha_info; - ha_info.type = ND_OPT_HOME_AGENT_INFO; - ha_info.length = 1; - ha_info.flags_reserved = - (iface->AdvMobRtrSupportFlag)?ND_OPT_HAI_FLAG_SUPPORT_MR:0; - ha_info.preference = htons(iface->HomeAgentPreference); - ha_info.lifetime = htons(iface->HomeAgentLifetime); + ha_info.type = ND_OPT_HOME_AGENT_INFO; + ha_info.length = 1; + ha_info.flags_reserved = (iface->AdvMobRtrSupportFlag) ? ND_OPT_HAI_FLAG_SUPPORT_MR : 0; + ha_info.preference = htons(iface->HomeAgentPreference); + ha_info.lifetime = htons(iface->HomeAgentLifetime); buff_dest = len; send_ra_inc_len(&len, sizeof(ha_info)); @@ -511,14 +471,9 @@ send_ra(struct Interface *iface, struct in6_addr *dest) return 0; } -int really_send( - struct in6_addr const *dest, - unsigned int if_index, - struct in6_addr if_addr, - unsigned char * buff, - size_t len) +int really_send(struct in6_addr const *dest, unsigned int if_index, struct in6_addr if_addr, unsigned char *buff, size_t len) { - char __attribute__((aligned(8))) chdr[CMSG_SPACE(sizeof(struct in6_pktinfo))]; + char __attribute__ ((aligned(8))) chdr[CMSG_SPACE(sizeof(struct in6_pktinfo))]; struct in6_pktinfo *pkt_info; struct msghdr mhdr; struct cmsghdr *cmsg; @@ -531,33 +486,31 @@ int really_send( addr.sin6_port = htons(IPPROTO_ICMPV6); memcpy(&addr.sin6_addr, dest, sizeof(struct in6_addr)); - - iov.iov_len = len; + iov.iov_len = len; iov.iov_base = (caddr_t) buff; memset(chdr, 0, sizeof(chdr)); - cmsg = (struct cmsghdr *) chdr; + cmsg = (struct cmsghdr *)chdr; - cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); + cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); cmsg->cmsg_level = IPPROTO_IPV6; - cmsg->cmsg_type = IPV6_PKTINFO; + cmsg->cmsg_type = IPV6_PKTINFO; pkt_info = (struct in6_pktinfo *)CMSG_DATA(cmsg); pkt_info->ipi6_ifindex = if_index; memcpy(&pkt_info->ipi6_addr, &if_addr, sizeof(struct in6_addr)); #ifdef HAVE_SIN6_SCOPE_ID - if (IN6_IS_ADDR_LINKLOCAL(&addr.sin6_addr) || - IN6_IS_ADDR_MC_LINKLOCAL(&addr.sin6_addr)) - addr.sin6_scope_id = if_index; + if (IN6_IS_ADDR_LINKLOCAL(&addr.sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&addr.sin6_addr)) + addr.sin6_scope_id = if_index; #endif memset(&mhdr, 0, sizeof(mhdr)); - mhdr.msg_name = (caddr_t)&addr; + mhdr.msg_name = (caddr_t) & addr; mhdr.msg_namelen = sizeof(struct sockaddr_in6); mhdr.msg_iov = &iov; mhdr.msg_iovlen = 1; - mhdr.msg_control = (void *) cmsg; + mhdr.msg_control = (void *)cmsg; mhdr.msg_controllen = sizeof(chdr); err = sendmsg(sock, &mhdr, 0); diff --git a/socket.c b/socket.c index 6b9068b6..97da8868 100644 --- a/socket.c +++ b/socket.c @@ -19,31 +19,28 @@ /* Note: these are applicable to receiving sockopts only */ #if defined IPV6_HOPLIMIT && !defined IPV6_RECVHOPLIMIT -# define IPV6_RECVHOPLIMIT IPV6_HOPLIMIT +#define IPV6_RECVHOPLIMIT IPV6_HOPLIMIT #endif #if defined IPV6_PKTINFO && !defined IPV6_RECVPKTINFO -# define IPV6_RECVPKTINFO IPV6_PKTINFO +#define IPV6_RECVPKTINFO IPV6_PKTINFO #endif -int -open_icmpv6_socket(void) +int open_icmpv6_socket(void) { int sock; struct icmp6_filter filter; int err, val; - sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); - if (sock < 0) - { + sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); + if (sock < 0) { flog(LOG_ERR, "can't create socket(AF_INET6): %s", strerror(errno)); return (-1); } val = 1; err = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val)); - if (err < 0) - { + if (err < 0) { flog(LOG_ERR, "setsockopt(IPV6_RECVPKTINFO): %s", strerror(errno)); return (-1); } @@ -54,33 +51,28 @@ open_icmpv6_socket(void) #else err = setsockopt(sock, IPPROTO_IPV6, IPV6_CHECKSUM, &val, sizeof(val)); #endif - if (err < 0) - { + if (err < 0) { flog(LOG_ERR, "setsockopt(IPV6_CHECKSUM): %s", strerror(errno)); return (-1); } val = 255; err = setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &val, sizeof(val)); - if (err < 0) - { + if (err < 0) { flog(LOG_ERR, "setsockopt(IPV6_UNICAST_HOPS): %s", strerror(errno)); return (-1); } val = 255; err = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)); - if (err < 0) - { + if (err < 0) { flog(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS): %s", strerror(errno)); return (-1); } - #ifdef IPV6_RECVHOPLIMIT val = 1; err = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &val, sizeof(val)); - if (err < 0) - { + if (err < 0) { flog(LOG_ERR, "setsockopt(IPV6_RECVHOPLIMIT): %s", strerror(errno)); return (-1); } @@ -94,10 +86,8 @@ open_icmpv6_socket(void) ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter); ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter); - err = setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, - sizeof(filter)); - if (err < 0) - { + err = setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, sizeof(filter)); + if (err < 0) { flog(LOG_ERR, "setsockopt(ICMPV6_FILTER): %s", strerror(errno)); return (-1); } diff --git a/timer.c b/timer.c index 0a1301bf..deda1c7c 100644 --- a/timer.c +++ b/timer.c @@ -15,8 +15,7 @@ #include "radvd.h" -struct timeval -next_timeval(double next) +struct timeval next_timeval(double next) { struct timeval tv; gettimeofday(&tv, NULL); @@ -25,19 +24,16 @@ next_timeval(double next) return tv; } -int -timevaldiff(struct timeval const *a, struct timeval const *b) +int timevaldiff(struct timeval const *a, struct timeval const *b) { - int msec; - msec = (a->tv_sec - b->tv_sec) * 1000; - msec += (a->tv_usec - b->tv_usec) / 1000; - return msec; + int msec; + msec = (a->tv_sec - b->tv_sec) * 1000; + msec += (a->tv_usec - b->tv_usec) / 1000; + return msec; } - /* Returns when the next time should expire in milliseconds. */ -int -next_time_msec(struct Interface const * iface) +int next_time_msec(struct Interface const *iface) { struct timeval tv; int retval; @@ -46,13 +42,11 @@ next_time_msec(struct Interface const * iface) return retval >= 1 ? retval : 1; } -int -expired(struct Interface const * iface) +int expired(struct Interface const *iface) { struct timeval tv; gettimeofday(&tv, NULL); - if(timevaldiff(&iface->next_multicast, &tv) > 0) + if (timevaldiff(&iface->next_multicast, &tv) > 0) return 0; return 1; } - diff --git a/util.c b/util.c index cd221740..ebdad8a8 100644 --- a/util.c +++ b/util.c @@ -16,63 +16,57 @@ #include "includes.h" #include "radvd.h" -double -rand_between(double lower, double upper) +double rand_between(double lower, double upper) { return ((upper - lower) / (RAND_MAX + 1.0) * rand() + lower); } -void -print_addr(struct in6_addr *addr, char *str) +void print_addr(struct in6_addr *addr, char *str) { const char *res; /* XXX: overflows 'str' if it isn't big enough */ res = inet_ntop(AF_INET6, (void *)addr, str, INET6_ADDRSTRLEN); - if (res == NULL) - { + if (res == NULL) { flog(LOG_ERR, "print_addr: inet_ntop: %s", strerror(errno)); strcpy(str, "[invalid address]"); } } /* Check if an in6_addr exists in the rdnss list */ -int -check_rdnss_presence(struct AdvRDNSS *rdnss, struct in6_addr *addr) +int check_rdnss_presence(struct AdvRDNSS *rdnss, struct in6_addr *addr) { while (rdnss) { - if ( !memcmp(&rdnss->AdvRDNSSAddr1, addr, sizeof(struct in6_addr)) - || !memcmp(&rdnss->AdvRDNSSAddr2, addr, sizeof(struct in6_addr)) - || !memcmp(&rdnss->AdvRDNSSAddr3, addr, sizeof(struct in6_addr)) ) - break; /* rdnss address found in the list */ + if (!memcmp(&rdnss->AdvRDNSSAddr1, addr, sizeof(struct in6_addr)) + || !memcmp(&rdnss->AdvRDNSSAddr2, addr, sizeof(struct in6_addr)) + || !memcmp(&rdnss->AdvRDNSSAddr3, addr, sizeof(struct in6_addr))) + break; /* rdnss address found in the list */ else - rdnss = rdnss->next; /* no match */ + rdnss = rdnss->next; /* no match */ } return (rdnss != NULL); } /* Check if a suffix exists in the dnssl list */ -int -check_dnssl_presence(struct AdvDNSSL *dnssl, const char *suffix) +int check_dnssl_presence(struct AdvDNSSL *dnssl, const char *suffix) { int i; while (dnssl) { for (i = 0; i < dnssl->AdvDNSSLNumber; i++) { if (strcmp(dnssl->AdvDNSSLSuffixes[i], suffix) == 0) - break; /* suffix found in the list */ + break; /* suffix found in the list */ } if (i != dnssl->AdvDNSSLNumber) break; - dnssl = dnssl->next; /* no match */ + dnssl = dnssl->next; /* no match */ } return (dnssl != NULL); } /* Like read(), but retries in case of partial read */ -ssize_t -readn(int fd, void *buf, size_t count) +ssize_t readn(int fd, void *buf, size_t count) { size_t n = 0; while (count > 0) { @@ -92,8 +86,7 @@ readn(int fd, void *buf, size_t count) } /* Like write(), but retries in case of partial write */ -ssize_t -writen(int fd, const void *buf, size_t count) +ssize_t writen(int fd, const void *buf, size_t count) { size_t n = 0; while (count > 0) {