*/
#include <stdio.h>
+#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/uio.h>
f.flags |= IF_MULTIACCESS | IF_BROADCAST | IF_MULTICAST;
else
f.flags |= IF_MULTIACCESS; /* NBMA */
- if_update(&f);
+
+ ifi = if_update(&f);
+
+ if (!scan)
+ if_end_partial_update(ifi);
}
}
static void
-nl_parse_addr(struct nlmsghdr *h)
+nl_parse_addr(struct nlmsghdr *h, int scan)
{
struct ifaddrmsg *i;
struct rtattr *a[IFA_ANYCAST+1];
ifi->index, ifi->name,
new ? "added" : "removed",
ifa.ip, ifa.flags, ifa.prefix, ifa.pxlen, ifa.brd, ifa.opposite);
+
if (new)
ifa_update(&ifa);
else
ifa_delete(&ifa);
+
+ if (!scan)
+ if_end_partial_update(ifi);
}
void
nl_request_dump(RTM_GETADDR);
while (h = nl_get_scan())
if (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR)
- nl_parse_addr(h);
+ nl_parse_addr(h, 1);
else
log(L_DEBUG "nl_scan_ifaces: Unknown packet received (type=%d)", h->nlmsg_type);
net *net = net_get(p->p.table, dst, i->rtm_dst_len);
rta ra = {
- .proto = &p->p,
+ .src= p->p.main_source,
.source = RTS_INHERIT,
.scope = SCOPE_UNIVERSE,
.cast = RTC_UNICAST
memcpy(&ra.gw, RTA_DATA(a[RTA_GATEWAY]), sizeof(ra.gw));
ipa_ntoh(ra.gw);
+#ifdef IPV6
/* Silently skip strange 6to4 routes */
if (ipa_in_net(ra.gw, IPA_NONE, 96))
return;
+#endif
ng = neigh_find2(&p->p, &ra.gw, ra.iface,
(i->rtm_flags & RTNH_F_ONLINK) ? NEF_ONLINK : 0);
else
{
ra.dest = RTD_DEVICE;
-
- /*
- * In Linux IPv6, 'native' device routes have proto
- * RTPROT_BOOT and not RTPROT_KERNEL (which they have in
- * IPv4 and which is expected). We cannot distinguish
- * 'native' and user defined device routes, so we ignore all
- * such device routes and for consistency, we have the same
- * behavior in IPv4. Anyway, users should use RTPROT_STATIC
- * for their 'alien' routes.
- */
-
- if (i->rtm_protocol == RTPROT_BOOT)
- src = KRT_SRC_KERNEL;
}
break;
case RTM_NEWADDR:
case RTM_DELADDR:
DBG("KRT: Received async address notification (%d)\n", h->nlmsg_type);
- nl_parse_addr(h);
+ nl_parse_addr(h, 0);
break;
default:
DBG("KRT: Received unknown async notification (%d)\n", h->nlmsg_type);
sock *sk;
struct sockaddr_nl sa;
int fd;
- static int nl_open_tried = 0;
- if (nl_open_tried)
+ if (nl_async_sk)
return;
- nl_open_tried = 1;
DBG("KRT: Opening async netlink socket\n");
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0)
{
log(L_ERR "Unable to bind asynchronous rtnetlink socket: %m");
+ close(fd);
return;
}
+ nl_async_rx_buffer = xmalloc(NL_RX_SIZE);
+
sk = nl_async_sk = sk_new(krt_pool);
sk->type = SK_MAGIC;
sk->rx_hook = nl_async_hook;
sk->fd = fd;
if (sk_open(sk))
bug("Netlink: sk_open failed");
-
- if (!nl_async_rx_buffer)
- nl_async_rx_buffer = xmalloc(NL_RX_SIZE);
}
/*
static u8 nl_cf_table[(NL_NUM_TABLES+7) / 8];
void
-krt_sys_start(struct krt_proto *p, int first)
+krt_sys_start(struct krt_proto *p)
{
nl_table_map[KRT_CF->sys.table_id] = p;
- if (first)
- {
- nl_open();
- nl_open_async();
- }
+
+ nl_open();
+ nl_open_async();
}
void
-krt_sys_shutdown(struct krt_proto *p UNUSED, int last UNUSED)
+krt_sys_shutdown(struct krt_proto *p UNUSED)
{
+ nl_table_map[KRT_CF->sys.table_id] = NULL;
}
int