Updated for new scope handling.

Also, provide proper address scopes in struct ifa.
This commit is contained in:
Martin Mares 2000-06-01 12:58:41 +00:00
parent 0f32f2a65a
commit 4a91150175
3 changed files with 22 additions and 3 deletions

View file

@ -100,7 +100,7 @@ krt_parse_entry(byte *ent, struct krt_proto *p)
if (flags & RTF_GATEWAY) if (flags & RTF_GATEWAY)
{ {
neighbor *ng = neigh_find(&p->p, &gw, 0); neighbor *ng = neigh_find(&p->p, &gw, 0);
if (ng) if (ng && ng->scope)
a.iface = ng->iface; a.iface = ng->iface;
else else
/* FIXME: Remove this warning? Handle it somehow... */ /* FIXME: Remove this warning? Handle it somehow... */

View file

@ -321,6 +321,7 @@ nl_parse_addr(struct nlmsghdr *h)
int new = h->nlmsg_type == RTM_NEWADDR; int new = h->nlmsg_type == RTM_NEWADDR;
struct ifa ifa; struct ifa ifa;
struct iface *ifi; struct iface *ifi;
int scope;
if (!(i = nl_checkin(h, sizeof(*i))) || !nl_parse_attrs(IFA_RTA(i), a, sizeof(a))) if (!(i = nl_checkin(h, sizeof(*i))) || !nl_parse_attrs(IFA_RTA(i), a, sizeof(a)))
return; return;
@ -355,6 +356,7 @@ nl_parse_addr(struct nlmsghdr *h)
ifa.iface = ifi; ifa.iface = ifi;
if (i->ifa_flags & IFA_F_SECONDARY) if (i->ifa_flags & IFA_F_SECONDARY)
ifa.flags |= IA_SECONDARY; ifa.flags |= IA_SECONDARY;
/* IFA_LOCAL can be unset for IPv6 interfaces */ /* IFA_LOCAL can be unset for IPv6 interfaces */
memcpy(&ifa.ip, RTA_DATA(a[IFA_LOCAL] ? : a[IFA_ADDRESS]), sizeof(ifa.ip)); memcpy(&ifa.ip, RTA_DATA(a[IFA_LOCAL] ? : a[IFA_ADDRESS]), sizeof(ifa.ip));
ipa_ntoh(ifa.ip); ipa_ntoh(ifa.ip);
@ -389,6 +391,14 @@ nl_parse_addr(struct nlmsghdr *h)
ifa.prefix = ipa_and(ifa.ip, netmask); ifa.prefix = ipa_and(ifa.ip, netmask);
} }
scope = ipa_classify(ifa.ip);
if (scope < 0)
{
log(L_ERR "KIF: Invalid interface address %I", ifa.ip);
return;
}
ifa.scope = scope & IADDR_SCOPE_MASK;
DBG("KIF: IF%d(%s): %s IPA %I, flg %x, net %I/%d, brd %I, opp %I\n", DBG("KIF: IF%d(%s): %s IPA %I, flg %x, net %I/%d, brd %I, opp %I\n",
ifi->index, ifi->name, ifi->index, ifi->name,
new ? "added" : "removed", new ? "added" : "removed",
@ -664,7 +674,7 @@ nl_parse_route(struct nlmsghdr *h, int scan)
memcpy(&ra.gw, RTA_DATA(a[RTA_GATEWAY]), sizeof(ra.gw)); memcpy(&ra.gw, RTA_DATA(a[RTA_GATEWAY]), sizeof(ra.gw));
ipa_ntoh(ra.gw); ipa_ntoh(ra.gw);
ng = neigh_find(&p->p, &ra.gw, 0); ng = neigh_find(&p->p, &ra.gw, 0);
if (ng) if (ng && ng->scope)
ra.iface = ng->iface; ra.iface = ng->iface;
else else
/* FIXME: Remove this warning? Handle it somehow... */ /* FIXME: Remove this warning? Handle it somehow... */

View file

@ -35,7 +35,7 @@ scan_ifs(struct ifreq *r, int cnt)
char *err, *colon; char *err, *colon;
unsigned fl; unsigned fl;
ip_addr netmask; ip_addr netmask;
int l; int l, scope;
if_start_update(); if_start_update();
for (cnt /= sizeof(struct ifreq); cnt; cnt--, r++) for (cnt /= sizeof(struct ifreq); cnt; cnt--, r++)
@ -115,6 +115,14 @@ scan_ifs(struct ifreq *r, int cnt)
) )
i.flags |= IF_MULTICAST; i.flags |= IF_MULTICAST;
scope = ipa_classify(a.ip);
if (scope < 0)
{
log(L_ERR "%s: Invalid address", i.name);
goto bad;
}
a.scope = scope & IADDR_SCOPE_MASK;
if (a.pxlen < 32) if (a.pxlen < 32)
{ {
a.brd = ipa_or(a.prefix, ipa_not(ipa_mkmask(a.pxlen))); a.brd = ipa_or(a.prefix, ipa_not(ipa_mkmask(a.pxlen)));
@ -132,6 +140,7 @@ scan_ifs(struct ifreq *r, int cnt)
} }
else else
a.brd = a.opposite; a.brd = a.opposite;
a.scope = SCOPE_UNIVERSE;
if (ioctl(if_scan_sock, SIOCGIFMTU, r) < 0) if (ioctl(if_scan_sock, SIOCGIFMTU, r) < 0)
{ err = "SIOCGIFMTU"; goto faulty; } { err = "SIOCGIFMTU"; goto faulty; }