}
#endif
+#ifdef SIN6_LEN
+/* Calculate sin6_len value for netmask socket value. */
+static int sin6_masklen(struct in6_addr mask)
+{
+ struct sockaddr_in6 sin6;
+ char *p, *lim;
+ int len;
+
+ if (IN6_IS_ADDR_UNSPECIFIED(&mask))
+ return sizeof(long);
+
+ sin6.sin6_addr = mask;
+ len = sizeof(struct sockaddr_in6);
+
+ lim = (char *)&sin6.sin6_addr;
+ p = lim + sizeof(sin6.sin6_addr);
+
+ while (*--p == 0 && p >= lim)
+ len--;
+
+ return len;
+}
+#endif /* SIN6_LEN */
+
/* Interface between zebra message and rtm message. */
static int kernel_rtm_ipv4(int cmd, const struct prefix *p,
const struct nexthop_group *ng, uint32_t metric)
{
- struct sockaddr_in *mask = NULL;
- struct sockaddr_in sin_dest, sin_mask, sin_gate;
+ union sockunion *mask = NULL;
+ union sockunion sin_dest, sin_mask, sin_gate;
#ifdef __OpenBSD__
struct sockaddr_mpls smpls;
#endif
if (IS_ZEBRA_DEBUG_RIB)
prefix2str(p, prefix_buf, sizeof(prefix_buf));
- memset(&sin_dest, 0, sizeof(struct sockaddr_in));
- sin_dest.sin_family = AF_INET;
+ memset(&sin_dest, 0, sizeof(sin_dest));
+ sin_dest.sin.sin_family = AF_INET;
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- sin_dest.sin_len = sizeof(struct sockaddr_in);
+ sin_dest.sin.sin_len = sizeof(sin_dest);
#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
- sin_dest.sin_addr = p->u.prefix4;
+ sin_dest.sin.sin_addr = p->u.prefix4;
- memset(&sin_mask, 0, sizeof(struct sockaddr_in));
+ memset(&sin_mask, 0, sizeof(sin_mask));
- memset(&sin_gate, 0, sizeof(struct sockaddr_in));
- sin_gate.sin_family = AF_INET;
+ memset(&sin_gate, 0, sizeof(sin_gate));
+ sin_gate.sin.sin_family = AF_INET;
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- sin_gate.sin_len = sizeof(struct sockaddr_in);
+ sin_gate.sin.sin_len = sizeof(sin_gate);
#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
/* Make gateway. */
|| (cmd == RTM_DELETE)) {
if (nexthop->type == NEXTHOP_TYPE_IPV4
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
- sin_gate.sin_addr = nexthop->gate.ipv4;
+ sin_gate.sin.sin_addr = nexthop->gate.ipv4;
gate = 1;
}
if (nexthop->type == NEXTHOP_TYPE_IFINDEX
if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE) {
struct in_addr loopback;
loopback.s_addr = htonl(INADDR_LOOPBACK);
- sin_gate.sin_addr = loopback;
+ sin_gate.sin.sin_addr = loopback;
bh_type = nexthop->bh_type;
gate = 1;
}
if (gate && p->prefixlen == 32)
mask = NULL;
else {
- masklen2ip(p->prefixlen, &sin_mask.sin_addr);
- sin_mask.sin_family = AF_INET;
+ masklen2ip(p->prefixlen,
+ &sin_mask.sin.sin_addr);
+ sin_mask.sin.sin_family = AF_INET;
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- sin_mask.sin_len =
- sin_masklen(sin_mask.sin_addr);
+ sin_mask.sin.sin_len =
+ sin_masklen(sin_mask.sin.sin_addr);
#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
mask = &sin_mask;
}
smplsp = (union sockunion *)&smpls;
#endif
- error = rtm_write(cmd, (union sockunion *)&sin_dest,
- (union sockunion *)mask,
- gate ? (union sockunion *)&sin_gate
- : NULL,
- smplsp, ifindex, bh_type, metric);
+ error = rtm_write(cmd, &sin_dest, mask,
+ gate ? &sin_gate : NULL, smplsp,
+ ifindex, bh_type, metric);
if (IS_ZEBRA_DEBUG_KERNEL) {
if (!gate) {
"%s: %s: attention! gate not found for re",
__func__, prefix_buf);
} else
- inet_ntop(AF_INET, &sin_gate.sin_addr,
+ inet_ntop(AF_INET,
+ &sin_gate.sin.sin_addr,
gate_buf, INET_ADDRSTRLEN);
}
return 0; /*XXX*/
}
-#ifdef SIN6_LEN
-/* Calculate sin6_len value for netmask socket value. */
-static int sin6_masklen(struct in6_addr mask)
-{
- struct sockaddr_in6 sin6;
- char *p, *lim;
- int len;
-
- if (IN6_IS_ADDR_UNSPECIFIED(&mask))
- return sizeof(long);
-
- sin6.sin6_addr = mask;
- len = sizeof(struct sockaddr_in6);
-
- lim = (char *)&sin6.sin6_addr;
- p = lim + sizeof(sin6.sin6_addr);
-
- while (*--p == 0 && p >= lim)
- len--;
-
- return len;
-}
-#endif /* SIN6_LEN */
-
/* Interface between zebra message and rtm message. */
static int kernel_rtm_ipv6(int cmd, const struct prefix *p,
const struct nexthop_group *ng, uint32_t metric)
{
- struct sockaddr_in6 *mask;
- struct sockaddr_in6 sin_dest, sin_mask, sin_gate;
+ union sockunion *mask;
+ union sockunion sin_dest, sin_mask, sin_gate;
#ifdef __OpenBSD__
struct sockaddr_mpls smpls;
#endif
int error;
enum blackhole_type bh_type = BLACKHOLE_UNSPEC;
- memset(&sin_dest, 0, sizeof(struct sockaddr_in6));
- sin_dest.sin6_family = AF_INET6;
+ memset(&sin_dest, 0, sizeof(sin_dest));
+ sin_dest.sin6.sin6_family = AF_INET6;
#ifdef SIN6_LEN
- sin_dest.sin6_len = sizeof(struct sockaddr_in6);
+ sin_dest.sin6.sin6_len = sizeof(sin_dest);
#endif /* SIN6_LEN */
- sin_dest.sin6_addr = p->u.prefix6;
+ sin_dest.sin6.sin6_addr = p->u.prefix6;
- memset(&sin_mask, 0, sizeof(struct sockaddr_in6));
+ memset(&sin_mask, 0, sizeof(sin_mask));
- memset(&sin_gate, 0, sizeof(struct sockaddr_in6));
- sin_gate.sin6_family = AF_INET6;
+ memset(&sin_gate, 0, sizeof(sin_gate));
+ sin_gate.sin6.sin6_family = AF_INET6;
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- sin_gate.sin6_len = sizeof(struct sockaddr_in6);
+ sin_gate.sin6.sin6_len = sizeof(sin_gate);
#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
/* Make gateway. */
|| (cmd == RTM_DELETE)) {
if (nexthop->type == NEXTHOP_TYPE_IPV6
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
- sin_gate.sin6_addr = nexthop->gate.ipv6;
+ sin_gate.sin6.sin6_addr = nexthop->gate.ipv6;
gate = 1;
}
if (nexthop->type == NEXTHOP_TYPE_IFINDEX
(a).s6_addr[3] = (i)&0xff; \
} while (0)
- if (gate && IN6_IS_ADDR_LINKLOCAL(&sin_gate.sin6_addr))
- SET_IN6_LINKLOCAL_IFINDEX(sin_gate.sin6_addr, ifindex);
+ if (gate && IN6_IS_ADDR_LINKLOCAL(&sin_gate.sin6.sin6_addr))
+ SET_IN6_LINKLOCAL_IFINDEX(sin_gate.sin6.sin6_addr,
+ ifindex);
#endif /* KAME */
if (gate && p->prefixlen == 128)
mask = NULL;
else {
- masklen2ip6(p->prefixlen, &sin_mask.sin6_addr);
- sin_mask.sin6_family = AF_INET6;
+ masklen2ip6(p->prefixlen, &sin_mask.sin6.sin6_addr);
+ sin_mask.sin6.sin6_family = AF_INET6;
#ifdef SIN6_LEN
- sin_mask.sin6_len = sin6_masklen(sin_mask.sin6_addr);
+ sin_mask.sin6.sin6_len =
+ sin6_masklen(sin_mask.sin6.sin6_addr);
#endif /* SIN6_LEN */
mask = &sin_mask;
}
smplsp = (union sockunion *)&smpls;
#endif
- error = rtm_write(cmd, (union sockunion *)&sin_dest,
- (union sockunion *)mask,
- gate ? (union sockunion *)&sin_gate : NULL,
+ error = rtm_write(cmd, &sin_dest, mask, gate ? &sin_gate : NULL,
smplsp, ifindex, bh_type, metric);
/* Update installed nexthop info on success */