0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 12:48:43 +00:00

RAdv: Style updates

Adapt the naming conventions to be a bit closer to the other protocols.

proto_radv -> radv_proto
struct radv_proto *ra -> struct radv_proto *p
struct proto *p -> struct proto *P
This commit is contained in:
Michal 'vorner' Vaner 2017-08-08 14:40:51 +02:00 committed by Ondrej Zajicek (work)
parent 637ed49868
commit 1f182675c8
3 changed files with 77 additions and 76 deletions

View File

@ -82,8 +82,8 @@ static struct radv_prefix_config default_prefix = {
static struct radv_prefix_config *
radv_prefix_match(struct radv_iface *ifa, struct ifa *a)
{
struct proto *p = &ifa->ra->p;
struct radv_config *cf = (struct radv_config *) (p->cf);
struct radv_proto *p = ifa->ra;
struct radv_config *cf = (struct radv_config *) (p->p.cf);
struct radv_prefix_config *pc;
if (a->scope <= SCOPE_LINK)
@ -238,8 +238,8 @@ radv_prepare_dnssl(struct radv_iface *ifa, list *dnssl_list, char **buf, char *b
static void
radv_prepare_ra(struct radv_iface *ifa)
{
struct proto_radv *ra = ifa->ra;
struct radv_config *cf = (struct radv_config *) (ra->p.cf);
struct radv_proto *p = ifa->ra;
struct radv_config *cf = (struct radv_config *) (p->p.cf);
struct radv_iface_config *ic = ifa->cf;
char *buf = ifa->sk->tbuf;
@ -251,7 +251,7 @@ radv_prepare_ra(struct radv_iface *ifa)
pkt->code = 0;
pkt->checksum = 0;
pkt->current_hop_limit = ic->current_hop_limit;
pkt->router_lifetime = (ra->active || !ic->default_lifetime_sensitive) ?
pkt->router_lifetime = (p->active || !ic->default_lifetime_sensitive) ?
htons(ic->default_lifetime) : 0;
pkt->flags = (ic->managed ? OPT_RA_MANAGED : 0) |
(ic->other_config ? OPT_RA_OTHER_CFG : 0) |
@ -281,7 +281,7 @@ radv_prepare_ra(struct radv_iface *ifa)
if (buf + sizeof(struct radv_opt_prefix) > bufend)
{
log(L_WARN "%s: Too many prefixes on interface %s", ra->p.name, ifa->iface->name);
log(L_WARN "%s: Too many prefixes on interface %s", p->p.name, ifa->iface->name);
goto done;
}
@ -291,9 +291,9 @@ radv_prepare_ra(struct radv_iface *ifa)
op->pxlen = addr->pxlen;
op->flags = (pc->onlink ? OPT_PX_ONLINK : 0) |
(pc->autonomous ? OPT_PX_AUTONOMOUS : 0);
op->valid_lifetime = (ra->active || !pc->valid_lifetime_sensitive) ?
op->valid_lifetime = (p->active || !pc->valid_lifetime_sensitive) ?
htonl(pc->valid_lifetime) : 0;
op->preferred_lifetime = (ra->active || !pc->preferred_lifetime_sensitive) ?
op->preferred_lifetime = (p->active || !pc->preferred_lifetime_sensitive) ?
htonl(pc->preferred_lifetime) : 0;
op->reserved = 0;
op->prefix = addr->prefix;
@ -323,7 +323,7 @@ radv_prepare_ra(struct radv_iface *ifa)
void
radv_send_ra(struct radv_iface *ifa, int shutdown)
{
struct proto_radv *ra = ifa->ra;
struct radv_proto *p = ifa->ra;
/* We store prepared RA in tbuf */
if (!ifa->plen)
@ -351,7 +351,7 @@ static int
radv_rx_hook(sock *sk, uint size)
{
struct radv_iface *ifa = sk->data;
struct proto_radv *ra = ifa->ra;
struct radv_proto *p = ifa->ra;
/* We want just packets from sk->iface */
if (sk->lifindex != sk->iface->index)

View File

@ -47,7 +47,7 @@ static void
radv_timer(timer *tm)
{
struct radv_iface *ifa = tm->data;
struct proto_radv *ra = ifa->ra;
struct radv_proto *p = ifa->ra;
RADV_TRACE(D_EVENTS, "Timer fired on %s", ifa->iface->name);
@ -72,7 +72,7 @@ static char* ev_name[] = { NULL, "Init", "Change", "RS" };
void
radv_iface_notify(struct radv_iface *ifa, int event)
{
struct proto_radv *ra = ifa->ra;
struct radv_proto *p = ifa->ra;
if (!ifa->sk)
return;
@ -102,21 +102,21 @@ radv_iface_notify(struct radv_iface *ifa, int event)
}
static void
radv_iface_notify_all(struct proto_radv *ra, int event)
radv_iface_notify_all(struct radv_proto *p, int event)
{
struct radv_iface *ifa;
WALK_LIST(ifa, ra->iface_list)
WALK_LIST(ifa, p->iface_list)
radv_iface_notify(ifa, event);
}
static struct radv_iface *
radv_iface_find(struct proto_radv *ra, struct iface *what)
radv_iface_find(struct radv_proto *p, struct iface *what)
{
struct radv_iface *ifa;
WALK_LIST(ifa, ra->iface_list)
WALK_LIST(ifa, p->iface_list)
if (ifa->iface == what)
return ifa;
@ -127,11 +127,11 @@ static void
radv_iface_add(struct object_lock *lock)
{
struct radv_iface *ifa = lock->data;
struct proto_radv *ra = ifa->ra;
struct radv_proto *p = ifa->ra;
if (! radv_sk_open(ifa))
{
log(L_ERR "%s: Socket open failed on interface %s", ra->p.name, ifa->iface->name);
log(L_ERR "%s: Socket open failed on interface %s", p->p.name, ifa->iface->name);
return;
}
@ -150,24 +150,24 @@ find_lladdr(struct iface *iface)
}
static void
radv_iface_new(struct proto_radv *ra, struct iface *iface, struct radv_iface_config *cf)
radv_iface_new(struct radv_proto *p, struct iface *iface, struct radv_iface_config *cf)
{
pool *pool = ra->p.pool;
pool *pool = p->p.pool;
struct radv_iface *ifa;
RADV_TRACE(D_EVENTS, "Adding interface %s", iface->name);
ifa = mb_allocz(pool, sizeof(struct radv_iface));
ifa->ra = ra;
ifa->ra = p;
ifa->cf = cf;
ifa->iface = iface;
add_tail(&ra->iface_list, NODE ifa);
add_tail(&p->iface_list, NODE ifa);
ifa->addr = find_lladdr(iface);
if (!ifa->addr)
{
log(L_ERR "%s: Cannot find link-locad addr on interface %s", ra->p.name, iface->name);
log(L_ERR "%s: Cannot find link-locad addr on interface %s", p->p.name, iface->name);
return;
}
@ -193,7 +193,7 @@ radv_iface_new(struct proto_radv *ra, struct iface *iface, struct radv_iface_con
static void
radv_iface_remove(struct radv_iface *ifa)
{
struct proto_radv *ra = ifa->ra;
struct radv_proto *p = ifa->ra;
RADV_TRACE(D_EVENTS, "Removing interface %s", ifa->iface->name);
rem_node(NODE ifa);
@ -206,10 +206,10 @@ radv_iface_remove(struct radv_iface *ifa)
}
static void
radv_if_notify(struct proto *p, unsigned flags, struct iface *iface)
radv_if_notify(struct proto *P, unsigned flags, struct iface *iface)
{
struct proto_radv *ra = (struct proto_radv *) p;
struct radv_config *cf = (struct radv_config *) (p->cf);
struct radv_proto *p = (struct radv_proto *) P;
struct radv_config *cf = (struct radv_config *) (P->cf);
if (iface->flags & IF_IGNORE)
return;
@ -220,12 +220,12 @@ radv_if_notify(struct proto *p, unsigned flags, struct iface *iface)
iface_patt_find(&cf->patt_list, iface, NULL);
if (ic)
radv_iface_new(ra, iface, ic);
radv_iface_new(p, iface, ic);
return;
}
struct radv_iface *ifa = radv_iface_find(ra, iface);
struct radv_iface *ifa = radv_iface_find(p, iface);
if (!ifa)
return;
@ -240,9 +240,9 @@ radv_if_notify(struct proto *p, unsigned flags, struct iface *iface)
}
static void
radv_ifa_notify(struct proto *p, unsigned flags UNUSED, struct ifa *a)
radv_ifa_notify(struct proto *P, unsigned flags UNUSED, struct ifa *a)
{
struct proto_radv *ra = (struct proto_radv *) p;
struct radv_proto *p = (struct radv_proto *) P;
if (a->flags & IA_SECONDARY)
return;
@ -250,7 +250,7 @@ radv_ifa_notify(struct proto *p, unsigned flags UNUSED, struct ifa *a)
if (a->scope <= SCOPE_LINK)
return;
struct radv_iface *ifa = radv_iface_find(ra, a->iface);
struct radv_iface *ifa = radv_iface_find(p, a->iface);
if (ifa)
radv_iface_notify(ifa, RA_EV_CHANGE);
@ -264,10 +264,10 @@ static inline int radv_net_match_trigger(struct radv_config *cf, net *n)
}
int
radv_import_control(struct proto *p, rte **new, ea_list **attrs UNUSED, struct linpool *pool UNUSED)
radv_import_control(struct proto *P, rte **new, ea_list **attrs UNUSED, struct linpool *pool UNUSED)
{
// struct proto_radv *ra = (struct proto_radv *) p;
struct radv_config *cf = (struct radv_config *) (p->cf);
// struct radv_proto *p = (struct radv_proto *) P;
struct radv_config *cf = (struct radv_config *) (P->cf);
if (radv_net_match_trigger(cf, (*new)->net))
return RIC_PROCESS;
@ -276,61 +276,62 @@ 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, rtable *tbl UNUSED, net *n, rte *new, rte *old UNUSED, ea_list *attrs UNUSED)
{
struct proto_radv *ra = (struct proto_radv *) p;
struct radv_config *cf = (struct radv_config *) (p->cf);
struct radv_proto *p = (struct radv_proto *) P;
struct radv_config *cf = (struct radv_config *) (P->cf);
if (radv_net_match_trigger(cf, n))
{
u8 old_active = ra->active;
ra->active = !!new;
u8 old_active = p->active;
p->active = !!new;
if (ra->active == old_active)
if (p->active == old_active)
return;
if (ra->active)
if (p->active)
RADV_TRACE(D_EVENTS, "Triggered");
else
RADV_TRACE(D_EVENTS, "Suppressed");
radv_iface_notify_all(ra, RA_EV_CHANGE);
radv_iface_notify_all(p, RA_EV_CHANGE);
}
}
static int
radv_check_active(struct proto_radv *ra)
radv_check_active(struct radv_proto *p)
{
struct radv_config *cf = (struct radv_config *) (ra->p.cf);
struct radv_config *cf = (struct radv_config *) (p->p.cf);
if (! cf->trigger_valid)
return 1;
return rt_examine(ra->p.table, cf->trigger_prefix, cf->trigger_pxlen,
&(ra->p), ra->p.cf->out_filter);
return rt_examine(p->p.table, cf->trigger_prefix, cf->trigger_pxlen,
&(p->p), p->p.cf->out_filter);
}
static struct proto *
radv_init(struct proto_config *c)
{
struct proto *p = proto_new(c, sizeof(struct proto_radv));
struct proto *P = proto_new(c, sizeof(struct radv_proto));
p->accept_ra_types = RA_OPTIMAL;
p->import_control = radv_import_control;
p->rt_notify = radv_rt_notify;
p->if_notify = radv_if_notify;
p->ifa_notify = radv_ifa_notify;
return p;
P->accept_ra_types = RA_OPTIMAL;
P->import_control = radv_import_control;
P->rt_notify = radv_rt_notify;
P->if_notify = radv_if_notify;
P->ifa_notify = radv_ifa_notify;
return P;
}
static int
radv_start(struct proto *p)
radv_start(struct proto *P)
{
struct proto_radv *ra = (struct proto_radv *) p;
struct radv_config *cf = (struct radv_config *) (p->cf);
struct radv_proto *p = (struct radv_proto *) P;
struct radv_config *cf = (struct radv_config *) (P->cf);
init_list(&(ra->iface_list));
ra->active = !cf->trigger_valid;
init_list(&(p->iface_list));
p->active = !cf->trigger_valid;
return PS_UP;
}
@ -343,21 +344,21 @@ radv_iface_shutdown(struct radv_iface *ifa)
}
static int
radv_shutdown(struct proto *p)
radv_shutdown(struct proto *P)
{
struct proto_radv *ra = (struct proto_radv *) p;
struct radv_proto *p = (struct radv_proto *) P;
struct radv_iface *ifa;
WALK_LIST(ifa, ra->iface_list)
WALK_LIST(ifa, p->iface_list)
radv_iface_shutdown(ifa);
return PS_DOWN;
}
static int
radv_reconfigure(struct proto *p, struct proto_config *c)
radv_reconfigure(struct proto *P, struct proto_config *c)
{
struct proto_radv *ra = (struct proto_radv *) p;
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;
@ -369,13 +370,13 @@ 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 */
ra->active = radv_check_active(ra);
P->cf = c; /* radv_check_active() requires proper P->cf */
p->active = radv_check_active(p);
struct iface *iface;
WALK_LIST(iface, iface_list)
{
struct radv_iface *ifa = radv_iface_find(ra, iface);
struct radv_iface *ifa = radv_iface_find(p, iface);
struct radv_iface_config *ic = (struct radv_iface_config *)
iface_patt_find(&new->patt_list, iface, NULL);
@ -395,7 +396,7 @@ radv_reconfigure(struct proto *p, struct proto_config *c)
}
if (!ifa && ic)
radv_iface_new(ra, iface, ic);
radv_iface_new(p, iface, ic);
}
return 1;
@ -415,11 +416,11 @@ radv_copy_config(struct proto_config *dest, struct proto_config *src)
}
static void
radv_get_status(struct proto *p, byte *buf)
radv_get_status(struct proto *P, byte *buf)
{
struct proto_radv *ra = (struct proto_radv *) p;
struct radv_proto *p = (struct radv_proto *) P;
if (!ra->active)
if (!p->active)
strcpy(buf, "Suppressed");
}

View File

@ -114,7 +114,7 @@ struct radv_dnssl_config
};
struct proto_radv
struct radv_proto
{
struct proto p;
list iface_list; /* List of active ifaces */
@ -124,7 +124,7 @@ struct proto_radv
struct radv_iface
{
node n;
struct proto_radv *ra;
struct radv_proto *ra;
struct radv_iface_config *cf; /* Related config, must be updated in reconfigure */
struct iface *iface;
struct ifa *addr; /* Link-local address of iface */
@ -154,8 +154,8 @@ struct radv_iface
#else
#define RADV_FORCE_DEBUG 0
#endif
#define RADV_TRACE(flags, msg, args...) do { if ((ra->p.debug & flags) || RADV_FORCE_DEBUG) \
log(L_TRACE "%s: " msg, ra->p.name , ## args ); } while(0)
#define RADV_TRACE(flags, msg, args...) do { if ((p->p.debug & flags) || RADV_FORCE_DEBUG) \
log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
/* radv.c */