summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rtadvd/if.c
diff options
context:
space:
mode:
authorhrs <hrs@FreeBSD.org>2011-06-04 16:42:51 +0000
committerhrs <hrs@FreeBSD.org>2011-06-04 16:42:51 +0000
commit6bc38bb7763f3a319af31dd1c98897607c49bda8 (patch)
treebd1f48a8aea344bd00edc8b67d3114f655b9a9b7 /usr.sbin/rtadvd/if.c
parent5ea968aedea8b356417c669ff68b2bdbb7df25c3 (diff)
downloadFreeBSD-src-6bc38bb7763f3a319af31dd1c98897607c49bda8.zip
FreeBSD-src-6bc38bb7763f3a319af31dd1c98897607c49bda8.tar.gz
Fix various inconsistencies in symbol naming and data handling which
made the logic behind them unnecessarily complicated. This change is a preparation to add support of dynamically-added/removed interfaces and the link status changes in a more reliable way. Changes include: - Use queue(3) for linked-list manipulation. - Use consistent variable names. - Use (AF_INET6, s, d, sizeof(d)) instead of (AF_INET6, s, a, INET6_ADDRSTRLEN) for inet_ntop(). - style(9) fixes. No functional change in this commit.
Diffstat (limited to 'usr.sbin/rtadvd/if.c')
-rw-r--r--usr.sbin/rtadvd/if.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c
index 5cbf515..f500feb 100644
--- a/usr.sbin/rtadvd/if.c
+++ b/usr.sbin/rtadvd/if.c
@@ -51,22 +51,22 @@
#include "rtadvd.h"
#include "if.h"
-#define ROUNDUP(a, size) \
+#define ROUNDUP(a, size) \
(((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
-#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
- ((caddr_t)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
- sizeof(u_long)) :\
- sizeof(u_long)))
+#define NEXT_SA(ap) \
+ (ap) = (struct sockaddr *)((caddr_t)(ap) + \
+ ((ap)->sa_len ? ROUNDUP((ap)->sa_len, sizeof(u_long)) : \
+ sizeof(u_long)))
struct if_msghdr **iflist;
int iflist_init_ok;
size_t ifblock_size;
char *ifblock;
-static void get_iflist(char **buf, size_t *size);
-static void parse_iflist(struct if_msghdr ***ifmlist_p, char *buf,
- size_t bufsize);
+static void get_iflist(char **buf, size_t *size);
+static void parse_iflist(struct if_msghdr ***ifmlist_p,
+ char *buf, size_t bufsize);
static void
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
@@ -189,14 +189,14 @@ if_getflags(int ifindex, int oifflags)
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "<%s> socket: %s", __func__,
- strerror(errno));
+ strerror(errno));
return (oifflags & ~IFF_UP);
}
if_indextoname(ifindex, ifr.ifr_name);
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
syslog(LOG_ERR, "<%s> ioctl:SIOCGIFFLAGS: failed for %s",
- __func__, ifr.ifr_name);
+ __func__, ifr.ifr_name);
close(s);
return (oifflags & ~IFF_UP);
}
@@ -242,7 +242,6 @@ int
rtbuf_len(void)
{
size_t len;
-
int mib[6] = {CTL_NET, AF_ROUTE, 0, AF_INET6, NET_RT_DUMP, 0};
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
@@ -268,8 +267,8 @@ get_next_msg(char *buf, char *lim, int ifindex, size_t *lenp, int filter)
/* just for safety */
if (!rtm->rtm_msglen) {
syslog(LOG_WARNING, "<%s> rtm_msglen is 0 "
- "(buf=%p lim=%p rtm=%p)", __func__,
- buf, lim, rtm);
+ "(buf=%p lim=%p rtm=%p)", __func__,
+ buf, lim, rtm);
break;
}
if (FILTER_MATCH(rtm->rtm_type, filter) == 0) {
@@ -487,7 +486,7 @@ get_iflist(char **buf, size_t *size)
if (sysctl(mib, 6, NULL, size, NULL, 0) < 0) {
syslog(LOG_ERR, "<%s> sysctl: iflist size get failed",
- __func__);
+ __func__);
exit(1);
}
if ((*buf = malloc(*size)) == NULL) {
@@ -496,7 +495,7 @@ get_iflist(char **buf, size_t *size)
}
if (sysctl(mib, 6, *buf, size, NULL, 0) < 0) {
syslog(LOG_ERR, "<%s> sysctl: iflist get failed",
- __func__);
+ __func__);
exit(1);
}
return;
@@ -530,8 +529,8 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize)
for (ifm = (struct if_msghdr *)buf; ifm < (struct if_msghdr *)lim;) {
if (ifm->ifm_msglen == 0) {
syslog(LOG_WARNING, "<%s> ifm_msglen is 0 "
- "(buf=%p lim=%p ifm=%p)", __func__,
- buf, lim, ifm);
+ "(buf=%p lim=%p ifm=%p)", __func__,
+ buf, lim, ifm);
return;
}
@@ -539,10 +538,10 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize)
(*ifmlist_p)[ifm->ifm_index] = ifm;
} else {
syslog(LOG_ERR, "out of sync parsing NET_RT_IFLIST\n"
- "expected %d, got %d\n msglen = %d\n"
- "buf:%p, ifm:%p, lim:%p\n",
- RTM_IFINFO, ifm->ifm_type, ifm->ifm_msglen,
- buf, ifm, lim);
+ "expected %d, got %d\n msglen = %d\n"
+ "buf:%p, ifm:%p, lim:%p\n",
+ RTM_IFINFO, ifm->ifm_type, ifm->ifm_msglen,
+ buf, ifm, lim);
exit (1);
}
for (ifam = (struct ifa_msghdr *)
@@ -553,8 +552,8 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize)
/* just for safety */
if (!ifam->ifam_msglen) {
syslog(LOG_WARNING, "<%s> ifa_msglen is 0 "
- "(buf=%p lim=%p ifam=%p)", __func__,
- buf, lim, ifam);
+ "(buf=%p lim=%p ifam=%p)", __func__,
+ buf, lim, ifam);
return;
}
if (ifam->ifam_type != RTM_NEWADDR)
OpenPOWER on IntegriCloud