summaryrefslogtreecommitdiff
path: root/proto/radv
diff options
context:
space:
mode:
Diffstat (limited to 'proto/radv')
-rw-r--r--proto/radv/Makefile9
-rw-r--r--proto/radv/config.Y33
-rw-r--r--proto/radv/packets.c26
-rw-r--r--proto/radv/radv.c54
-rw-r--r--proto/radv/radv.h11
5 files changed, 75 insertions, 58 deletions
diff --git a/proto/radv/Makefile b/proto/radv/Makefile
index efc4d4af..05317eff 100644
--- a/proto/radv/Makefile
+++ b/proto/radv/Makefile
@@ -1,5 +1,6 @@
-source=radv.c packets.c
-root-rel=../../
-dir-name=proto/radv
+src := packets.c radv.c
+obj := $(src-o-files)
+$(all-daemon)
+$(cf-local)
-include ../../Rules
+tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
diff --git a/proto/radv/config.Y b/proto/radv/config.Y
index da300667..b5f4b5f2 100644
--- a/proto/radv/config.Y
+++ b/proto/radv/config.Y
@@ -41,6 +41,7 @@ CF_ADDTO(proto, radv_proto)
radv_proto_start: proto_start RADV
{
this_proto = proto_config_new(&proto_radv, $1);
+
init_list(&RADV_CFG->patt_list);
init_list(&RADV_CFG->pref_list);
init_list(&RADV_CFG->rdnss_list);
@@ -49,15 +50,12 @@ radv_proto_start: proto_start RADV
radv_proto_item:
proto_item
+ | proto_channel
| INTERFACE radv_iface
| 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;
- RADV_CFG->trigger_valid = 1;
- }
+ | TRIGGER net_ip6 { RADV_CFG->trigger = $2; }
;
radv_proto_opts:
@@ -93,14 +91,14 @@ radv_iface_item:
| MIN DELAY expr { RADV_IFACE->min_delay = $3; if ($3 <= 0) cf_error("Min delay must be positive"); }
| MANAGED bool { RADV_IFACE->managed = $2; }
| OTHER CONFIG bool { RADV_IFACE->other_config = $3; }
- | LINK MTU expr { RADV_IFACE->link_mtu = $3; if ($3 < 0) cf_error("Link MTU must be 0 or positive"); }
- | REACHABLE TIME expr { RADV_IFACE->reachable_time = $3; if (($3 < 0) || ($3 > 3600000)) cf_error("Reachable time must be in range 0-3600000"); }
- | RETRANS TIMER expr { RADV_IFACE->retrans_timer = $3; if ($3 < 0) cf_error("Retrans timer must be 0 or positive"); }
- | CURRENT HOP LIMIT expr { RADV_IFACE->current_hop_limit = $4; if (($4 < 0) || ($4 > 255)) cf_error("Current hop limit must be in range 0-255"); }
+ | LINK MTU expr { RADV_IFACE->link_mtu = $3; }
+ | REACHABLE TIME expr { RADV_IFACE->reachable_time = $3; if ($3 > 3600000) cf_error("Reachable time must be in range 0-3600000"); }
+ | RETRANS TIMER expr { RADV_IFACE->retrans_timer = $3; }
+ | CURRENT HOP LIMIT expr { RADV_IFACE->current_hop_limit = $4; if ($4 > 255) cf_error("Current hop limit must be in range 0-255"); }
| DEFAULT LIFETIME expr radv_sensitive {
RADV_IFACE->default_lifetime = $3;
- if (($3 < 0) || ($3 > 9000)) cf_error("Default lifetime must be in range 0-9000");
- if ($4 != -1) RADV_IFACE->default_lifetime_sensitive = $4;
+ if ($3 > 9000) cf_error("Default lifetime must be in range 0-9000");
+ if ($4 != (uint) -1) RADV_IFACE->default_lifetime_sensitive = $4;
}
| DEFAULT PREFERENCE radv_preference { RADV_IFACE->default_preference = $3; }
| PREFIX radv_prefix { add_tail(&RADV_IFACE->pref_list, NODE this_radv_prefix); }
@@ -127,7 +125,7 @@ radv_iface_finish:
if ((ic->min_ra_int > 3) &&
(ic->min_ra_int > (ic->max_ra_int * 3 / 4)))
- cf_error("Min RA interval must be at most 3/4 * Max RA interval %d %d", ic->min_ra_int, ic->max_ra_int);
+ cf_error("Min RA interval must be at most 3/4 * Max RA interval");
if ((ic->default_lifetime > 0) && (ic->default_lifetime < ic->max_ra_int))
cf_error("Default lifetime must be either 0 or at least Max RA interval");
@@ -148,11 +146,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 = *(net_addr_ip6 *) &($1);
RADV_PREFIX->onlink = 1;
RADV_PREFIX->autonomous = 1;
@@ -166,13 +163,11 @@ radv_prefix_item:
| AUTONOMOUS bool { RADV_PREFIX->autonomous = $2; }
| VALID LIFETIME expr radv_sensitive {
RADV_PREFIX->valid_lifetime = $3;
- if ($3 < 0) cf_error("Valid lifetime must be 0 or positive");
- if ($4 != -1) RADV_PREFIX->valid_lifetime_sensitive = $4;
+ if ($4 != (uint) -1) RADV_PREFIX->valid_lifetime_sensitive = $4;
}
| PREFERRED LIFETIME expr radv_sensitive {
RADV_PREFIX->preferred_lifetime = $3;
- if ($3 < 0) cf_error("Preferred lifetime must be 0 or positive");
- if ($4 != -1) RADV_PREFIX->preferred_lifetime_sensitive = $4;
+ if ($4 != (uint) -1) RADV_PREFIX->preferred_lifetime_sensitive = $4;
}
;
diff --git a/proto/radv/packets.c b/proto/radv/packets.c
index 1c9837a4..15ca5738 100644
--- a/proto/radv/packets.c
+++ b/proto/radv/packets.c
@@ -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);
i++;
rcf = NODE_NEXT(rcf);
}
-
+
op->length = 1+2*i;
*buf += 8 * op->length;
}
@@ -273,6 +272,9 @@ radv_prepare_ra(struct radv_iface *ifa)
struct ifa *addr;
WALK_LIST(addr, ifa->iface->addrs)
{
+ if (addr->prefix.type != NET_IP6)
+ continue;
+
struct radv_prefix_config *pc;
pc = radv_prefix_match(ifa, addr);
@@ -288,7 +290,7 @@ radv_prepare_ra(struct radv_iface *ifa)
struct radv_opt_prefix *op = (void *) buf;
op->type = OPT_PREFIX;
op->length = 4;
- op->pxlen = addr->pxlen;
+ op->pxlen = net6_pxlen(&addr->prefix);
op->flags = (pc->onlink ? OPT_PX_ONLINK : 0) |
(pc->autonomous ? OPT_PX_AUTONOMOUS : 0);
op->valid_lifetime = (p->active || !pc->valid_lifetime_sensitive) ?
@@ -296,8 +298,7 @@ radv_prepare_ra(struct radv_iface *ifa)
op->preferred_lifetime = (p->active || !pc->preferred_lifetime_sensitive) ?
htonl(pc->preferred_lifetime) : 0;
op->reserved = 0;
- op->prefix = addr->prefix;
- ipa_hton(op->prefix);
+ op->prefix = ip6_hton(net6_prefix(&addr->prefix));
buf += sizeof(*op);
}
@@ -409,6 +410,7 @@ radv_sk_open(struct radv_iface *ifa)
{
sock *sk = sk_new(ifa->ra->p.pool);
sk->type = SK_IP;
+ sk->subtype = SK_IPV6;
sk->dport = ICMPV6_PROTO;
sk->saddr = ifa->addr->ip;
diff --git a/proto/radv/radv.c b/proto/radv/radv.c
index 91f9853d..b4b1bc58 100644
--- a/proto/radv/radv.c
+++ b/proto/radv/radv.c
@@ -143,7 +143,7 @@ find_lladdr(struct iface *iface)
{
struct ifa *a;
WALK_LIST(a, iface->addrs)
- if (a->scope == SCOPE_LINK)
+ if ((a->prefix.type == NET_IP6) && (a->scope == SCOPE_LINK))
return a;
return NULL;
@@ -256,11 +256,16 @@ radv_ifa_notify(struct proto *P, unsigned flags UNUSED, struct ifa *a)
radv_iface_notify(ifa, RA_EV_CHANGE);
}
-static inline int radv_net_match_trigger(struct radv_config *cf, net *n)
+static inline int
+radv_trigger_valid(struct radv_config *cf)
{
- return cf->trigger_valid &&
- (n->n.pxlen == cf->trigger_pxlen) &&
- ipa_equal(n->n.prefix, cf->trigger_prefix);
+ return cf->trigger.type != 0;
+}
+
+static inline int
+radv_net_match_trigger(struct radv_config *cf, net *n)
+{
+ return radv_trigger_valid(cf) && net_equal(n->n.addr, &cf->trigger);
}
int
@@ -276,7 +281,7 @@ radv_import_control(struct proto *P, rte **new, ea_list **attrs UNUSED, struct l
}
static void
-radv_rt_notify(struct proto *P, rtable *tbl UNUSED, net *n, rte *new, rte *old UNUSED, ea_list *attrs UNUSED)
+radv_rt_notify(struct proto *P, struct channel *ch UNUSED, net *n, rte *new, rte *old UNUSED, ea_list *attrs UNUSED)
{
struct radv_proto *p = (struct radv_proto *) P;
struct radv_config *cf = (struct radv_config *) (P->cf);
@@ -303,19 +308,30 @@ radv_check_active(struct radv_proto *p)
{
struct radv_config *cf = (struct radv_config *) (p->p.cf);
- if (! cf->trigger_valid)
+ if (!radv_trigger_valid(cf))
return 1;
- return rt_examine(p->p.table, cf->trigger_prefix, cf->trigger_pxlen,
- &(p->p), p->p.cf->out_filter);
+ struct channel *c = p->p.main_channel;
+ return rt_examine(c->table, &cf->trigger, &p->p, c->out_filter);
+}
+
+static void
+radv_postconfig(struct proto_config *CF)
+{
+ // struct radv_config *cf = (void *) CF;
+
+ /* Define default channel */
+ if (EMPTY_LIST(CF->channels))
+ channel_config_new(NULL, NET_IP6, CF);
}
static struct proto *
-radv_init(struct proto_config *c)
+radv_init(struct proto_config *CF)
{
- struct proto *P = proto_new(c, sizeof(struct radv_proto));
+ struct proto *P = proto_new(CF);
+
+ P->main_channel = proto_add_channel(P, proto_cf_main_channel(CF));
- P->accept_ra_types = RA_OPTIMAL;
P->import_control = radv_import_control;
P->rt_notify = radv_rt_notify;
P->if_notify = radv_if_notify;
@@ -331,7 +347,7 @@ radv_start(struct proto *P)
struct radv_config *cf = (struct radv_config *) (P->cf);
init_list(&(p->iface_list));
- p->active = !cf->trigger_valid;
+ p->active = !radv_trigger_valid(cf);
return PS_UP;
}
@@ -356,11 +372,11 @@ radv_shutdown(struct proto *P)
}
static int
-radv_reconfigure(struct proto *P, struct proto_config *c)
+radv_reconfigure(struct proto *P, struct proto_config *CF)
{
struct radv_proto *p = (struct radv_proto *) P;
// struct radv_config *old = (struct radv_config *) (p->cf);
- struct radv_config *new = (struct radv_config *) c;
+ struct radv_config *new = (struct radv_config *) CF;
/*
* The question is why there is a reconfigure function for RAdv if
@@ -370,7 +386,10 @@ radv_reconfigure(struct proto *P, struct proto_config *c)
* causing nodes to temporary remove their default routes.
*/
- P->cf = c; /* radv_check_active() requires proper P->cf */
+ if (!proto_configure_channel(P, &P->main_channel, proto_cf_main_channel(CF)))
+ return 0;
+
+ P->cf = CF; /* radv_check_active() requires proper P->cf */
p->active = radv_check_active(p);
struct iface *iface;
@@ -427,7 +446,10 @@ radv_get_status(struct proto *P, byte *buf)
struct protocol proto_radv = {
.name = "RAdv",
.template = "radv%d",
+ .channel_mask = NB_IP6,
+ .proto_size = sizeof(struct radv_proto),
.config_size = sizeof(struct radv_config),
+ .postconfig = radv_postconfig,
.init = radv_init,
.start = radv_start,
.shutdown = radv_shutdown,
diff --git a/proto/radv/radv.h b/proto/radv/radv.h
index 559a3f3f..35eea9ba 100644
--- a/proto/radv/radv.h
+++ b/proto/radv/radv.h
@@ -13,7 +13,7 @@
#include "lib/ip.h"
#include "lib/lists.h"
#include "lib/socket.h"
-#include "lib/timer.h"
+#include "sysdep/unix/timer.h"
#include "lib/resource.h"
#include "nest/protocol.h"
#include "nest/iface.h"
@@ -50,9 +50,7 @@ struct radv_config
list rdnss_list; /* Global list of RDNSS configs (struct radv_rdnss_config) */
list dnssl_list; /* Global list of DNSSL configs (struct radv_dnssl_config) */
- ip_addr trigger_prefix; /* Prefix of a trigger route, if defined */
- u8 trigger_pxlen; /* Pxlen of a trigger route, if defined */
- u8 trigger_valid; /* Whether a trigger route is defined */
+ net_addr trigger; /* Prefix of a trigger route, if defined */
};
struct radv_iface_config
@@ -83,8 +81,7 @@ struct radv_iface_config
struct radv_prefix_config
{
node n;
- ip_addr prefix;
- uint pxlen;
+ net_addr_ip6 prefix;
u8 skip; /* Do not include this prefix to RA */
u8 onlink; /* Standard options from RFC 4861 */
@@ -100,7 +97,7 @@ struct radv_rdnss_config
node n;
u32 lifetime; /* Valid if lifetime_mult is 0 */
u16 lifetime_mult; /* Lifetime specified as multiple of max_ra_int */
- ip_addr server; /* IP address of recursive DNS server */
+ ip6_addr server; /* IP address of recursive DNS server */
};
struct radv_dnssl_config