Commit d44e686e authored by Ondřej Zajíček's avatar Ondřej Zajíček

Follow-up commit on integrated BIRD

Use net_addr for interface address prefixes, support net_addr in
configuration parser.
parent fe9f1a6d
......@@ -41,6 +41,8 @@ CF_DECLS
ip_addr a;
ip4_addr ip4;
ip6_addr ip6;
net_addr_union net;
net_addr *net_ptr;
struct symbol *s;
char *t;
struct rtable_config *r;
......@@ -78,10 +80,11 @@ CF_DECLS
%type <i32> expr_us
%type <time> datetime
%type <a> ipa ipa_raw
%type <px> prefix prefix_or_ipa
%type <t> text
%type <t> text_or_none
%type <t> opttext
%type <px> prefix
%type <net> net_ip4 net_ip6 net_ip net_or_ipa
%type <net_ptr> net_any
%type <t> text opttext
%nonassoc PREFIX_DUMMY
%left AND OR
......@@ -169,6 +172,25 @@ ipa_scope:
| '%' SYM { $$ = if_get_by_name($2->name); }
;
/* XXXX - symbols and tests */
net_ip4: IP4 pxlen { $$.ip4 = NET_ADDR_IP4($1, $2); }
net_ip6: IP6 pxlen { $$.ip6 = NET_ADDR_IP6($1, $2); }
net_ip: net_ip4 | net_ip6 ;
net_any: net_ip { $$ = cfg_alloc($1.n.length); net_copy($$, &($1.n)); }
net_or_ipa:
net_ip4
| net_ip6
| IP4 { $$.ip4 = NET_ADDR_IP4($1, IP4_MAX_PREFIX_LENGTH); }
| IP6 { $$.ip6 = NET_ADDR_IP6($1, IP6_MAX_PREFIX_LENGTH); }
;
prefix:
ipa pxlen {
if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
......@@ -176,11 +198,6 @@ prefix:
}
;
prefix_or_ipa:
prefix
| ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
;
pxlen:
'/' expr {
if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
......@@ -208,11 +225,6 @@ text:
}
;
text_or_none:
TEXT { $$ = $1; }
| { $$ = NULL; }
;
opttext:
TEXT
| /* empty */ { $$ = NULL; }
......
......@@ -24,8 +24,8 @@ typedef struct net_addr {
u8 type;
u8 pxlen;
u16 length;
u8 data[16];
u64 align[0];
u32 space[4];
} net_addr;
typedef struct net_addr_ip4 {
......@@ -207,6 +207,9 @@ int net_classify(const net_addr *N);
char * net_format(const net_addr *N, char *buf, int buflen);
int ipa_in_netX(const ip_addr A, const net_addr *N);
int net_in_netX(const net_addr *A, const net_addr *N);
#endif
......
......@@ -30,7 +30,7 @@ iface_patt_check(void)
struct iface_patt_node *pn;
WALK_LIST(pn, this_ipatt->ipn_list)
if (!pn->pattern || pn->pxlen)
if (!pn->pattern || pn->prefix.pxlen) /* XXXX */
cf_error("Interface name/mask expected, not IP prefix");
}
......@@ -284,9 +284,8 @@ iface_patt_node_init:
;
iface_patt_node_body:
TEXT { this_ipn->pattern = $1; this_ipn->prefix = IPA_NONE; this_ipn->pxlen = 0; }
| prefix_or_ipa { this_ipn->pattern = NULL; this_ipn->prefix = $1.addr; this_ipn->pxlen = $1.len; }
| TEXT prefix_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.addr; this_ipn->pxlen = $2.len; }
TEXT { this_ipn->pattern = $1; net_fill_ip6(&this_ipn->prefix, IP6_NONE, 0); /* XXXX */ }
| opttext net_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.n; }
;
iface_negate:
......@@ -479,11 +478,11 @@ r_args:
$$->prefix = $2.addr;
$$->pxlen = $2.len;
}
| r_args FOR prefix_or_ipa {
| r_args FOR net_or_ipa {
$$ = $1;
if ($$->pxlen != 256) cf_error("Only one prefix expected");
$$->prefix = $3.addr;
$$->pxlen = $3.len;
$$->prefix = IPA_NONE; /* XXXX */
$$->pxlen = 0; /* XXXX */
$$->show_for = 1;
}
| r_args TABLE SYM {
......
......@@ -46,7 +46,7 @@ list iface_list;
void
ifa_dump(struct ifa *a)
{
debug("\t%I, net %I/%-2d bc %I -> %I%s%s%s\n", a->ip, a->prefix, a->pxlen, a->brd, a->opposite,
debug("\t%I, net %N bc %I -> %I%s%s%s\n", a->ip, &a->prefix, a->brd, a->opposite,
(a->flags & IF_UP) ? "" : " DOWN",
(a->flags & IA_PRIMARY) ? "" : " SEC",
(a->flags & IA_PEER) ? "PEER" : "");
......@@ -141,10 +141,9 @@ ifa_send_notify(struct proto *p, unsigned c, struct ifa *a)
if (p->ifa_notify)
{
if (p->debug & D_IFACES)
log(L_TRACE "%s < %s address %I/%d on interface %s %s",
log(L_TRACE "%s < %s address %N on interface %s %s",
p->name, (a->flags & IA_PRIMARY) ? "primary" : "secondary",
a->prefix, a->pxlen, a->iface->name,
(c & IF_CHANGE_UP) ? "added" : "removed");
&a->prefix, a->iface->name, (c & IF_CHANGE_UP) ? "added" : "removed");
p->ifa_notify(p, c, a);
}
}
......@@ -500,8 +499,7 @@ ifa_recalc_all_primary_addresses(void)
static inline int
ifa_same(struct ifa *a, struct ifa *b)
{
return ipa_equal(a->ip, b->ip) && ipa_equal(a->prefix, b->prefix) &&
a->pxlen == b->pxlen;
return ipa_equal(a->ip, b->ip) && net_equal(&a->prefix, &b->prefix);
}
......@@ -586,7 +584,6 @@ ifa_delete(struct ifa *a)
u32
if_choose_router_id(struct iface_patt *mask, u32 old_id)
{
#ifndef IPV6
struct iface *i;
struct ifa *a, *b;
......@@ -599,6 +596,9 @@ if_choose_router_id(struct iface_patt *mask, u32 old_id)
WALK_LIST(a, i->addrs)
{
if (a->prefix.type != NET_IP4)
continue;
if (a->flags & IA_SECONDARY)
continue;
......@@ -623,10 +623,6 @@ if_choose_router_id(struct iface_patt *mask, u32 old_id)
log(L_INFO "Chosen router ID %R according to interface %s", id, b->iface->name);
return id;
#else
return 0;
#endif
}
/**
......@@ -669,17 +665,17 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a)
continue;
}
if (p->pxlen == 0)
if (p->prefix.pxlen == 0)
return pos;
if (!a)
continue;
if (ipa_in_net(a->ip, p->prefix, p->pxlen))
if (ipa_in_netX(a->ip, &p->prefix))
return pos;
if ((a->flags & IA_PEER) &&
ipa_in_net(a->opposite, p->prefix, p->pxlen))
ipa_in_netX(a->opposite, &p->prefix))
return pos;
continue;
......@@ -713,8 +709,7 @@ iface_plists_equal(struct iface_patt *pa, struct iface_patt *pb)
(!x->pattern && y->pattern) || /* This nasty lines where written by me... :-( Feela */
(!y->pattern && x->pattern) ||
((x->pattern != y->pattern) && strcmp(x->pattern, y->pattern)) ||
!ipa_equal(x->prefix, y->prefix) ||
(x->pxlen != y->pxlen))
!net_equal(&x->prefix, &y->prefix))
return 0;
x = (void *) x->n.next;
y = (void *) y->n.next;
......@@ -754,7 +749,7 @@ if_show_addr(struct ifa *a)
else
opp[0] = 0;
cli_msg(-1003, "\t%I/%d (%s%s, scope %s)",
a->ip, a->pxlen,
a->ip, a->prefix.pxlen,
(a->flags & IA_PRIMARY) ? "Primary" : (a->flags & IA_SECONDARY) ? "Secondary" : "Unselected",
opp, ip_scope_text(a->scope));
}
......@@ -804,7 +799,7 @@ if_show_summary(void)
WALK_LIST(i, iface_list)
{
if (i->addr)
bsprintf(addr, "%I/%d", i->addr->ip, i->addr->pxlen);
bsprintf(addr, "%I/%d", i->addr->ip, i->addr->prefix.pxlen);
else
addr[0] = 0;
cli_msg(-1005, "%-9s %-5s %s", i->name, (i->flags & IF_UP) ? "up" : "DOWN", addr);
......
......@@ -19,9 +19,8 @@ struct pool;
struct ifa { /* Interface address */
node n;
struct iface *iface; /* Interface this address belongs to */
net_addr prefix; /* Network prefix */
ip_addr ip; /* IP address of this host */
ip_addr prefix; /* Network prefix */
unsigned pxlen; /* Prefix length */
ip_addr brd; /* Broadcast address */
ip_addr opposite; /* Opposite end of a point-to-point link */
unsigned scope; /* Interface address scope */
......@@ -148,8 +147,7 @@ struct iface_patt_node {
node n;
int positive;
byte *pattern;
ip_addr prefix;
int pxlen;
net_addr prefix;
};
struct iface_patt {
......
......@@ -79,7 +79,7 @@ if_connected(ip_addr *a, struct iface *i, struct ifa **ap)
}
else
{
if (ipa_in_net(*a, b->prefix, b->pxlen))
if (ipa_in_netX(*a, &b->prefix))
{
#ifndef IPV6
if ((b->pxlen < (BITS_PER_IP_ADDRESS - 1)) &&
......
......@@ -45,7 +45,7 @@ dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
net *n;
DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
n = net_find_ipa(p->table, ad->prefix, ad->pxlen);
n = net_find(p->table, &ad->prefix);
if (!n)
{
DBG("dev_if_notify: device shutdown: prefix not found\n");
......@@ -77,7 +77,7 @@ dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
};
a = rta_lookup(&a0);
n = net_get_ipa(p->table, ad->prefix, ad->pxlen);
n = net_get(p->table, &ad->prefix);
e = rte_get_temp(a);
e->net = n;
e->pflags = 0;
......
......@@ -211,10 +211,10 @@ ospf_stubnet:
;
ospf_stubnet_start:
prefix {
net_ip {
this_stubnet = cfg_allocz(sizeof(struct ospf_stubnet_config));
add_tail(&this_area->stubnet_list, NODE this_stubnet);
this_stubnet->px = $1;
this_stubnet->prefix = $1.n;
this_stubnet->cost = COST_D;
}
;
......@@ -321,12 +321,11 @@ pref_list:
pref_item: pref_base pref_opt ';' ;
pref_base: prefix
pref_base: net_ip
{
this_pref = cfg_allocz(sizeof(struct area_net_config));
add_tail(this_nets, NODE this_pref);
this_pref->px.addr = $1.addr;
this_pref->px.len = $1.len;
this_pref->prefix = $1.n;
}
;
......
......@@ -74,7 +74,7 @@ ospf_send_hello(struct ospf_iface *ifa, int kind, struct ospf_neighbor *dirn)
((ifa->type == OSPF_IT_PTP) && !ifa->ptp_netmask))
ps->netmask = 0;
else
ps->netmask = htonl(u32_mkmask(ifa->addr->pxlen));
ps->netmask = htonl(u32_mkmask(ifa->addr->prefix.pxlen));
ps->helloint = ntohs(ifa->helloint);
ps->options = ifa->oa->options;
......@@ -198,7 +198,7 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
/* RFC 2328 10.5 */
/*
* We may not yet havethe associate neighbor, so we use Router ID from the
* We may not yet have the associate neighbor, so we use Router ID from the
* packet instead of one from the neighbor structure for log messages.
*/
u32 rcv_rid = ntohl(pkt->routerid);
......@@ -224,7 +224,7 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
int pxlen = u32_masklen(ntohl(ps->netmask));
if ((ifa->type != OSPF_IT_VLINK) &&
(ifa->type != OSPF_IT_PTP) &&
(pxlen != ifa->addr->pxlen))
(pxlen != ifa->addr->prefix.pxlen))
DROP("prefix length mismatch", pxlen);
neighbors = ps->neighbors;
......
......@@ -237,8 +237,8 @@ ospf_iface_down(struct ospf_iface *ifa)
OSPF_TRACE(D_EVENTS, "Removing interface %s (peer %I) from area %R",
ifa->ifname, ifa->addr->opposite, ifa->oa->areaid);
else
OSPF_TRACE(D_EVENTS, "Removing interface %s (%I/%d) from area %R",
ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen, ifa->oa->areaid);
OSPF_TRACE(D_EVENTS, "Removing interface %s (%N) from area %R",
ifa->ifname, &ifa->addr->prefix, ifa->oa->areaid);
/* First of all kill all the related vlinks */
WALK_LIST(iff, p->iface_list)
......@@ -550,8 +550,8 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i
OSPF_TRACE(D_EVENTS, "Adding interface %s (peer %I) to area %R",
iface->name, addr->opposite, oa->areaid);
else
OSPF_TRACE(D_EVENTS, "Adding interface %s (%I/%d) to area %R",
iface->name, addr->prefix, addr->pxlen, oa->areaid);
OSPF_TRACE(D_EVENTS, "Adding interface %s (%N) to area %R",
iface->name, &addr->prefix, oa->areaid);
pool = rp_new(p->p.pool, "OSPF Interface");
ifa = mb_allocz(pool, sizeof(struct ospf_iface));
......@@ -627,7 +627,7 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i
should be used). Because OSPFv3 iface is not subnet-specific,
there is no need for ipa_in_net() check */
if (ospf_is_v2(p) && !ipa_in_net(nb->ip, addr->prefix, addr->pxlen))
if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &addr->prefix))
continue;
if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
......@@ -640,7 +640,7 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i
add_tail(&oa->po->iface_list, NODE ifa);
struct object_lock *lock = olock_new(pool);
lock->addr = ospf_is_v2(p) ? ifa->addr->prefix : IPA_NONE;
lock->addr = ospf_is_v2(p) ? ipa_from_ip4(net4_prefix(&ifa->addr->prefix)) : IPA_NONE;
lock->type = OBJLOCK_IP;
lock->port = OSPF_PROTO;
lock->inst = ifa->instance_id;
......@@ -886,7 +886,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
WALK_LIST(nb, new->nbma_list)
{
/* See related note in ospf_iface_new() */
if (ospf_is_v2(p) && !ipa_in_net(nb->ip, ifa->addr->prefix, ifa->addr->pxlen))
if (ospf_is_v2(p) && !ipa_in_netX(nb->ip, &ifa->addr->prefix))
continue;
if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
......@@ -1073,6 +1073,9 @@ ospf_ifa_notify2(struct proto *P, uint flags, struct ifa *a)
{
struct ospf_proto *p = (struct ospf_proto *) P;
if (a->prefix.type != NET_IP4)
return;
if (a->flags & IA_SECONDARY)
return;
......@@ -1102,6 +1105,9 @@ ospf_ifa_notify3(struct proto *P, uint flags, struct ifa *a)
{
struct ospf_proto *p = (struct ospf_proto *) P;
if (a->prefix.type != NET_IP6)
return;
if (a->flags & IA_SECONDARY)
return;
......@@ -1154,6 +1160,9 @@ ospf_reconfigure_ifaces2(struct ospf_proto *p)
WALK_LIST(a, iface->addrs)
{
if (a->prefix.type != NET_IP4)
continue;
if (a->flags & IA_SECONDARY)
continue;
......@@ -1172,8 +1181,8 @@ ospf_reconfigure_ifaces2(struct ospf_proto *p)
continue;
/* Hard restart */
log(L_INFO "%s: Restarting interface %s (%I/%d) in area %R",
p->p.name, ifa->ifname, a->prefix, a->pxlen, s.oa->areaid);
log(L_INFO "%s: Restarting interface %s (%N) in area %R",
p->p.name, ifa->ifname, &a->prefix, s.oa->areaid);
ospf_iface_shutdown(ifa);
ospf_iface_remove(ifa);
}
......@@ -1197,6 +1206,9 @@ ospf_reconfigure_ifaces3(struct ospf_proto *p)
WALK_LIST(a, iface->addrs)
{
if (a->prefix.type != NET_IP6)
continue;
if (a->flags & IA_SECONDARY)
continue;
......@@ -1328,7 +1340,7 @@ ospf_iface_info(struct ospf_iface *ifa)
else if (ifa->addr->flags & IA_PEER)
cli_msg(-1015, "Interface %s (peer %I)", ifa->ifname, ifa->addr->opposite);
else
cli_msg(-1015, "Interface %s (%I/%d)", ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen);
cli_msg(-1015, "Interface %s (%N)", ifa->ifname, ifa->addr->prefix);
cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more);
cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
......
......@@ -114,7 +114,6 @@ add_area_nets(struct ospf_area *oa, struct ospf_area_config *ac)
struct ospf_proto *p = oa->po;
struct area_net_config *anc;
struct area_net *an;
net_addr net;
fib_init(&oa->net_fib, p->p.pool, ospf_is_v2(p) ? NET_IP4 : NET_IP6,
sizeof(struct area_net), OFFSETOF(struct area_net, fn), 0, NULL);
......@@ -123,17 +122,13 @@ add_area_nets(struct ospf_area *oa, struct ospf_area_config *ac)
WALK_LIST(anc, ac->net_list)
{
/* XXXX we should dispatch by ospf version, not by px.addr */
net_fill_ipa(&net, anc->px.addr, anc->px.len);
an = fib_get(&oa->net_fib, &net);
an = fib_get(&oa->net_fib, &anc->prefix);
an->hidden = anc->hidden;
}
WALK_LIST(anc, ac->enet_list)
{
/* XXXX ditto */
net_fill_ipa(&net, anc->px.addr, anc->px.len);
an = fib_get(&oa->enet_fib, &net);
an = fib_get(&oa->enet_fib, &anc->prefix);
an->hidden = anc->hidden;
an->tag = anc->tag;
}
......
......@@ -125,7 +125,7 @@ struct ospf_area_config
struct area_net_config
{
node n;
struct prefix px;
net_addr prefix;
u32 tag;
u8 hidden;
};
......@@ -142,7 +142,7 @@ struct area_net
struct ospf_stubnet_config
{
node n;
struct prefix px;
net_addr prefix;
u32 cost;
u8 hidden;
u8 summary;
......
......@@ -236,7 +236,7 @@ ospf_rx_hook(sock *sk, int len)
return 1;
int src_local, dst_local, dst_mcast;
src_local = ipa_in_net(sk->faddr, ifa->addr->prefix, ifa->addr->pxlen);
src_local = ipa_in_netX(sk->faddr, &ifa->addr->prefix);
dst_local = ipa_equal(sk->laddr, ifa->addr->ip);
dst_mcast = ipa_equal(sk->laddr, ifa->all_routers) || ipa_equal(sk->laddr, ifa->des_routers);
......
......@@ -629,12 +629,12 @@ configured_stubnet(struct ospf_area *oa, struct ifa *a)
{
if (sn->summary)
{
if (ipa_in_net(a->prefix, sn->px.addr, sn->px.len) && (a->pxlen >= sn->px.len))
if (net_in_netX(&a->prefix, &sn->prefix))
return 1;
}
else
{
if (ipa_equal(a->prefix, sn->px.addr) && (a->pxlen == sn->px.len))
if (net_equal(&a->prefix, &sn->prefix))
return 1;
}
}
......@@ -782,7 +782,8 @@ prepare_rt2_lsa_body(struct ospf_proto *p, struct ospf_area *oa)
(ifa->type == OSPF_IT_PTMP))
add_rt2_lsa_link(p, LSART_STUB, ipa_to_u32(ifa->addr->ip), 0xffffffff, 0);
else
add_rt2_lsa_link(p, LSART_STUB, ipa_to_u32(ifa->addr->prefix), u32_mkmask(ifa->addr->pxlen), ifa->cost);
add_rt2_lsa_link(p, LSART_STUB, ip4_to_u32(net4_prefix(&ifa->addr->prefix)),
u32_mkmask(net4_pxlen(&ifa->addr->prefix)), ifa->cost);
i++;
ifa->rt_pos_end = i;
......@@ -791,7 +792,8 @@ prepare_rt2_lsa_body(struct ospf_proto *p, struct ospf_area *oa)
struct ospf_stubnet_config *sn;
WALK_LIST(sn, oa->ac->stubnet_list)
if (!sn->hidden)
add_rt2_lsa_link(p, LSART_STUB, ipa_to_u32(sn->px.addr), u32_mkmask(sn->px.len), sn->cost), i++;
add_rt2_lsa_link(p, LSART_STUB, ip4_to_u32(net4_prefix(&sn->prefix)),
u32_mkmask(net4_pxlen(&sn->prefix)), sn->cost), i++;
struct ospf_lsa_rt *rt = p->lsab;
/* Store number of links in lower half of options */
......@@ -908,7 +910,7 @@ prepare_net2_lsa_body(struct ospf_proto *p, struct ospf_iface *ifa)
ASSERT(p->lsab_used == 0);
net = lsab_alloc(p, sizeof(struct ospf_lsa_net) + 4 * nodes);
net->optx = u32_mkmask(ifa->addr->pxlen);
net->optx = u32_mkmask(ifa->addr->prefix.pxlen);
net->routers[0] = p->router_id;
WALK_LIST(n, ifa->neigh_list)
......@@ -1179,7 +1181,7 @@ use_gw_for_fwaddr(struct ospf_proto *p, ip_addr gw, struct iface *iface)
WALK_LIST(ifa, p->iface_list)
if ((ifa->iface == iface) &&
(!ospf_is_v2(p) || ipa_in_net(gw, ifa->addr->prefix, ifa->addr->pxlen)))
(!ospf_is_v2(p) || ipa_in_netX(gw, &ifa->addr->prefix)))
return 1;
return 0;
......@@ -1217,7 +1219,8 @@ find_surrogate_fwaddr(struct ospf_proto *p, struct ospf_area *oa)
{
WALK_LIST(a, ifa->iface->addrs)
{
if ((a->flags & IA_SECONDARY) ||
if ((a->prefix.type != NET_IP6) ||
(a->flags & IA_SECONDARY) ||
(a->flags & IA_PEER) ||
(a->scope <= SCOPE_LINK))
continue;
......@@ -1310,12 +1313,11 @@ ospf_rt_notify(struct proto *P, rtable *tbl UNUSED, net *n, rte *new, rte *old U
*/
static inline void
lsab_put_prefix(struct ospf_proto *p, ip6_addr prefix, u32 pxlen, u32 cost)
lsab_put_prefix(struct ospf_proto *p, net_addr *net, u32 cost)
{
net_addr_ip6 net = NET_ADDR_IP6(prefix, pxlen);
void *buf = lsab_alloc(p, IPV6_PREFIX_SPACE(pxlen));
u8 flags = (pxlen < IP6_MAX_PREFIX_LENGTH) ? 0 : OPT_PX_LA;
ospf_put_ipv6_prefix(buf, (net_addr *) &net, flags, cost);
void *buf = lsab_alloc(p, IPV6_PREFIX_SPACE(net6_pxlen(net)));
u8 flags = (net6_pxlen(net) < IP6_MAX_PREFIX_LENGTH) ? 0 : OPT_PX_LA;
ospf_put_ipv6_prefix(buf, net, flags, cost);
}
static void
......@@ -1333,11 +1335,12 @@ prepare_link_lsa_body(struct ospf_proto *p, struct ospf_iface *ifa)
struct ifa *a;
WALK_LIST(a, ifa->iface->addrs)
{
if ((a->flags & IA_SECONDARY) ||
(a->scope < SCOPE_SITE))
if ((a->prefix.type != NET_IP6) ||
(a->flags & IA_SECONDARY) ||
(a->scope <= SCOPE_LINK))
continue;
lsab_put_prefix(p, a->prefix, a->pxlen, 0);
lsab_put_prefix(p, &a->prefix, 0);
i++;
}
......@@ -1404,12 +1407,13 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa)
struct ifa *a;
WALK_LIST(a, ifa->iface->addrs)
{
if ((a->flags & IA_SECONDARY) ||
if ((a->prefix.type != NET_IP6) ||
(a->flags & IA_SECONDARY) ||
(a->flags & IA_PEER) ||
(a->scope <= SCOPE_LINK))
continue;
if (((a->pxlen < IP6_MAX_PREFIX_LENGTH) && net_lsa) ||
if (((a->prefix.pxlen < IP6_MAX_PREFIX_LENGTH) && net_lsa) ||
configured_stubnet(oa, a))
continue;
......@@ -1417,11 +1421,12 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa)
(ifa->state == OSPF_IS_LOOP) ||
(ifa->type == OSPF_IT_PTMP))
{
lsab_put_prefix(p, a->ip, IP6_MAX_PREFIX_LENGTH, 0);
net_addr_ip6 net = NET_ADDR_IP6(a->ip, IP6_MAX_PREFIX_LENGTH);
lsab_put_prefix(p, (net_addr *) &net, 0);
host_addr = 1;
}
else
lsab_put_prefix(p, a->prefix, a->pxlen, ifa->cost);
lsab_put_prefix(p, &a->prefix, ifa->cost);
i++;
}
......@@ -1432,8 +1437,8 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa)
WALK_LIST(sn, oa->ac->stubnet_list)
if (!sn->hidden)
{
lsab_put_prefix(p, sn->px.addr, sn->px.len, sn->cost);
if (sn->px.len == IP6_MAX_PREFIX_LENGTH)
lsab_put_prefix(p, &sn->prefix, sn->cost);
if (sn->prefix.pxlen == IP6_MAX_PREFIX_LENGTH)
host_addr = 1;
i++;
}
......@@ -1450,11 +1455,14 @@ prepare_prefix_rt_lsa_body(struct ospf_proto *p, struct ospf_area *oa)
struct ifa *a;
WALK_LIST(a, ifa->iface->addrs)
{
if ((a->flags & IA_SECONDARY) || (a->scope <= SCOPE_LINK))
if ((a->prefix.type != NET_IP6) ||
(a->flags & IA_SECONDARY) ||
(a->scope <= SCOPE_LINK))
continue;
/* Found some IP */
lsab_put_prefix(p, a->ip, IP6_MAX_PREFIX_LENGTH, 0);
net_addr_ip6 net = NET_ADDR_IP6(a->ip, IP6_MAX_PREFIX_LENGTH);
lsab_put_prefix(p, (net_addr *) &net, 0);
i++;
goto done;
}
......
......@@ -53,9 +53,8 @@ radv_proto_item:
| PREFIX radv_prefix { add_tail(&RADV_CFG->pref_list, NODE this_radv_prefix); }
| RDNSS { init_list(&radv_dns_list); } radv_rdnss { add_tail_list(&RADV_CFG->rdnss_list, &radv_dns_list); }
| DNSSL { init_list(&radv_dns_list); } radv_dnssl { add_tail_list(&RADV_CFG->dnssl_list, &radv_dns_list); }
| TRIGGER prefix {
RADV_CFG->trigger_prefix = $2.addr;
RADV_CFG->trigger_pxlen = $2.len;
| TRIGGER net_any {
RADV_CFG->trigger = $2;
RADV_CFG->trigger_valid = 1;
}
;
......@@ -148,11 +147,10 @@ radv_iface:
radv_iface_start iface_patt_list_nopx radv_iface_opt_list radv_iface_finish;
radv_prefix_start: prefix
radv_prefix_start: net_ip6
{
this_radv_prefix = cfg_allocz(sizeof(struct radv_prefix_config));
RADV_PREFIX->prefix = $1.addr;
RADV_PREFIX->pxlen = $1.len;
RADV_PREFIX->prefix = $1.ip6;
RADV_PREFIX->onlink = 1;
RADV_PREFIX->autonomous = 1;
......
......@@ -38,7 +38,7 @@ struct radv_opt_prefix
u32 valid_lifetime;
u32 preferred_lifetime;
u32 reserved;
ip_addr prefix;
ip6_addr prefix;
};
#define OPT_PX_ONLINK 0x80
......@@ -58,7 +58,7 @@ struct radv_opt_rdnss
u8 length;
u16 reserved;
u32 lifetime;
ip_addr servers[];
ip6_addr servers[];
};
struct radv_opt_dnssl
......@@ -90,11 +90,11 @@ radv_prefix_match(struct radv_iface *ifa, struct ifa *a)
return NULL;
WALK_LIST(pc, ifa->cf->pref_list)
if ((a->pxlen >= pc->pxlen) && ipa_in_net(a->prefix, pc->prefix, pc->pxlen))
if (net_in_netX(&a->prefix, (net_addr *) &pc->prefix))
return pc;
WALK_LIST(pc, cf->pref_list)
if ((a->pxlen >= pc->pxlen) && ipa_in_net(a->prefix, pc->prefix, pc->pxlen))
if (net_in_netX(&a->prefix, (net_addr *) &pc->prefix))
return pc;
return &default_prefix;
......@@ -109,7 +109,7 @@ radv_prepare_rdnss(struct radv_iface *ifa, list *rdnss_list, char **buf, char *b
{
struct radv_rdnss_config *rcf_base = rcf;
struct radv_opt_rdnss *op = (void *) *buf;
int max_i = (bufend - *buf - sizeof(struct radv_opt_rdnss)) / sizeof(ip_addr);
int max_i = (bufend - *buf - sizeof(struct radv_opt_rdnss)) / sizeof(ip6_addr);
int i = 0;
if (max_i < 1)
......@@ -123,20 +123,19 @@ radv_prepare_rdnss(struct radv_iface *ifa, list *rdnss_list, char **buf, char *b
else
op->lifetime = htonl(rcf->lifetime);
while(NODE_VALID(rcf) &&
while(NODE_VALID(rcf) &&
(rcf->lifetime == rcf_base->lifetime) &&
(rcf->lifetime_mult == rcf_base->lifetime_mult))
{
if (i >= max_i)
goto too_much;
op->servers[i] = rcf->server;
ipa_hton(op->servers[i]);
op->servers[i] = ip6_hton(rcf->server);