zebra: Move rtadv to zebra_router

The rtadv setting was not per namespace it is per router.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2018-08-27 15:34:36 -04:00
parent 1c6fca1f62
commit a3be9fa1a7
3 changed files with 32 additions and 39 deletions

View File

@ -45,6 +45,7 @@
#include "zebra/zebra_ns.h" #include "zebra/zebra_ns.h"
#include "zebra/zebra_vrf.h" #include "zebra/zebra_vrf.h"
#include "zebra/zebra_errors.h" #include "zebra/zebra_errors.h"
#include "zebra/zebra_router.h"
extern struct zebra_privs_t zserv_privs; extern struct zebra_privs_t zserv_privs;
@ -391,8 +392,8 @@ static int rtadv_timer(struct thread *thread)
struct zebra_if *zif; struct zebra_if *zif;
int period; int period;
zns->rtadv.ra_timer = NULL; zrouter.rtadv.ra_timer = NULL;
if (zns->rtadv.adv_msec_if_count == 0) { if (zrouter.rtadv.adv_msec_if_count == 0) {
period = 1000; /* 1 s */ period = 1000; /* 1 s */
rtadv_event(zns, RTADV_TIMER, 1 /* 1 s */); rtadv_event(zns, RTADV_TIMER, 1 /* 1 s */);
} else { } else {
@ -424,7 +425,8 @@ static int rtadv_timer(struct thread *thread)
"Fast RA Rexmit on interface %s", "Fast RA Rexmit on interface %s",
ifp->name); ifp->name);
rtadv_send_packet(zns->rtadv.sock, ifp); rtadv_send_packet(zrouter.rtadv.sock,
ifp);
} else { } else {
zif->rtadv.AdvIntervalTimer -= period; zif->rtadv.AdvIntervalTimer -= period;
if (zif->rtadv.AdvIntervalTimer <= 0) { if (zif->rtadv.AdvIntervalTimer <= 0) {
@ -437,7 +439,8 @@ static int rtadv_timer(struct thread *thread)
zif->rtadv zif->rtadv
.MaxRtrAdvInterval; .MaxRtrAdvInterval;
rtadv_send_packet( rtadv_send_packet(
zns->rtadv.sock, ifp); zrouter.rtadv.sock,
ifp);
} }
} }
} }
@ -452,7 +455,7 @@ static void rtadv_process_solicit(struct interface *ifp)
struct zebra_ns *zns = zvrf->zns; struct zebra_ns *zns = zvrf->zns;
assert(zns); assert(zns);
rtadv_send_packet(zns->rtadv.sock, ifp); rtadv_send_packet(zrouter.rtadv.sock, ifp);
} }
/* /*
@ -649,7 +652,7 @@ static int rtadv_read(struct thread *thread)
struct zebra_ns *zns = THREAD_ARG(thread); struct zebra_ns *zns = THREAD_ARG(thread);
sock = THREAD_FD(thread); sock = THREAD_FD(thread);
zns->rtadv.ra_read = NULL; zrouter.rtadv.ra_read = NULL;
/* Register myself. */ /* Register myself. */
rtadv_event(zns, RTADV_READ, sock); rtadv_event(zns, RTADV_READ, sock);
@ -808,18 +811,18 @@ static void ipv6_nd_suppress_ra_set(struct interface *ifp,
if (zif->rtadv.AdvSendAdvertisements) { if (zif->rtadv.AdvSendAdvertisements) {
zif->rtadv.AdvSendAdvertisements = 0; zif->rtadv.AdvSendAdvertisements = 0;
zif->rtadv.AdvIntervalTimer = 0; zif->rtadv.AdvIntervalTimer = 0;
zns->rtadv.adv_if_count--; zrouter.rtadv.adv_if_count--;
if_leave_all_router(zns->rtadv.sock, ifp); if_leave_all_router(zrouter.rtadv.sock, ifp);
if (zns->rtadv.adv_if_count == 0) if (zrouter.rtadv.adv_if_count == 0)
rtadv_event(zns, RTADV_STOP, 0); rtadv_event(zns, RTADV_STOP, 0);
} }
} else { } else {
if (!zif->rtadv.AdvSendAdvertisements) { if (!zif->rtadv.AdvSendAdvertisements) {
zif->rtadv.AdvSendAdvertisements = 1; zif->rtadv.AdvSendAdvertisements = 1;
zif->rtadv.AdvIntervalTimer = 0; zif->rtadv.AdvIntervalTimer = 0;
zns->rtadv.adv_if_count++; zrouter.rtadv.adv_if_count++;
if (zif->rtadv.MaxRtrAdvInterval >= 1000) { if (zif->rtadv.MaxRtrAdvInterval >= 1000) {
/* Enable Fast RA only when RA interval is in /* Enable Fast RA only when RA interval is in
@ -829,10 +832,11 @@ static void ipv6_nd_suppress_ra_set(struct interface *ifp,
RTADV_NUM_FAST_REXMITS; RTADV_NUM_FAST_REXMITS;
} }
if_join_all_router(zns->rtadv.sock, ifp); if_join_all_router(zrouter.rtadv.sock, ifp);
if (zns->rtadv.adv_if_count == 1) if (zrouter.rtadv.adv_if_count == 1)
rtadv_event(zns, RTADV_START, zns->rtadv.sock); rtadv_event(zns, RTADV_START,
zrouter.rtadv.sock);
} }
} }
} }
@ -972,10 +976,7 @@ DEFUN (ipv6_nd_ra_interval_msec,
VTY_DECLVAR_CONTEXT(interface, ifp); VTY_DECLVAR_CONTEXT(interface, ifp);
unsigned interval; unsigned interval;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
struct zebra_ns *zns;
zns = zvrf->zns;
interval = strtoul(argv[idx_number]->arg, NULL, 10); interval = strtoul(argv[idx_number]->arg, NULL, 10);
if ((zif->rtadv.AdvDefaultLifetime != -1 if ((zif->rtadv.AdvDefaultLifetime != -1
&& interval > (unsigned)zif->rtadv.AdvDefaultLifetime * 1000)) { && interval > (unsigned)zif->rtadv.AdvDefaultLifetime * 1000)) {
@ -985,10 +986,10 @@ DEFUN (ipv6_nd_ra_interval_msec,
} }
if (zif->rtadv.MaxRtrAdvInterval % 1000) if (zif->rtadv.MaxRtrAdvInterval % 1000)
zns->rtadv.adv_msec_if_count--; zrouter.rtadv.adv_msec_if_count--;
if (interval % 1000) if (interval % 1000)
zns->rtadv.adv_msec_if_count++; zrouter.rtadv.adv_msec_if_count++;
SET_FLAG(zif->rtadv.ra_configured, VTY_RA_INTERVAL_CONFIGURED); SET_FLAG(zif->rtadv.ra_configured, VTY_RA_INTERVAL_CONFIGURED);
zif->rtadv.MaxRtrAdvInterval = interval; zif->rtadv.MaxRtrAdvInterval = interval;
@ -1010,10 +1011,7 @@ DEFUN (ipv6_nd_ra_interval,
VTY_DECLVAR_CONTEXT(interface, ifp); VTY_DECLVAR_CONTEXT(interface, ifp);
unsigned interval; unsigned interval;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
struct zebra_ns *zns;
zns = zvrf->zns;
interval = strtoul(argv[idx_number]->arg, NULL, 10); interval = strtoul(argv[idx_number]->arg, NULL, 10);
if ((zif->rtadv.AdvDefaultLifetime != -1 if ((zif->rtadv.AdvDefaultLifetime != -1
&& interval > (unsigned)zif->rtadv.AdvDefaultLifetime)) { && interval > (unsigned)zif->rtadv.AdvDefaultLifetime)) {
@ -1023,7 +1021,7 @@ DEFUN (ipv6_nd_ra_interval,
} }
if (zif->rtadv.MaxRtrAdvInterval % 1000) if (zif->rtadv.MaxRtrAdvInterval % 1000)
zns->rtadv.adv_msec_if_count--; zrouter.rtadv.adv_msec_if_count--;
/* convert to milliseconds */ /* convert to milliseconds */
interval = interval * 1000; interval = interval * 1000;
@ -1049,14 +1047,9 @@ DEFUN (no_ipv6_nd_ra_interval,
{ {
VTY_DECLVAR_CONTEXT(interface, ifp); VTY_DECLVAR_CONTEXT(interface, ifp);
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
struct zebra_vrf *zvrf;
struct zebra_ns *zns;
zvrf = vrf_info_lookup(ifp->vrf_id);
zns = zvrf->zns;
if (zif->rtadv.MaxRtrAdvInterval % 1000) if (zif->rtadv.MaxRtrAdvInterval % 1000)
zns->rtadv.adv_msec_if_count--; zrouter.rtadv.adv_msec_if_count--;
UNSET_FLAG(zif->rtadv.ra_configured, VTY_RA_INTERVAL_CONFIGURED); UNSET_FLAG(zif->rtadv.ra_configured, VTY_RA_INTERVAL_CONFIGURED);
@ -1701,7 +1694,7 @@ static int rtadv_config_write(struct vty *vty, struct interface *ifp)
static void rtadv_event(struct zebra_ns *zns, enum rtadv_event event, int val) static void rtadv_event(struct zebra_ns *zns, enum rtadv_event event, int val)
{ {
struct rtadv *rtadv = &zns->rtadv; struct rtadv *rtadv = &zrouter.rtadv;
switch (event) { switch (event) {
case RTADV_START: case RTADV_START:
@ -1740,19 +1733,19 @@ static void rtadv_event(struct zebra_ns *zns, enum rtadv_event event, int val)
void rtadv_init(struct zebra_ns *zns) void rtadv_init(struct zebra_ns *zns)
{ {
zns->rtadv.sock = rtadv_make_socket(zns->ns_id); zrouter.rtadv.sock = rtadv_make_socket(zns->ns_id);
} }
void rtadv_terminate(struct zebra_ns *zns) void rtadv_terminate(struct zebra_ns *zns)
{ {
rtadv_event(zns, RTADV_STOP, 0); rtadv_event(zns, RTADV_STOP, 0);
if (zns->rtadv.sock >= 0) { if (zrouter.rtadv.sock >= 0) {
close(zns->rtadv.sock); close(zrouter.rtadv.sock);
zns->rtadv.sock = -1; zrouter.rtadv.sock = -1;
} }
zns->rtadv.adv_if_count = 0; zrouter.rtadv.adv_if_count = 0;
zns->rtadv.adv_msec_if_count = 0; zrouter.rtadv.adv_msec_if_count = 0;
} }
void rtadv_cmd_init(void) void rtadv_cmd_init(void)

View File

@ -53,10 +53,6 @@ struct zebra_ns {
struct route_table *if_table; struct route_table *if_table;
#if defined(HAVE_RTADV)
struct rtadv rtadv;
#endif /* HAVE_RTADV */
/* Back pointer */ /* Back pointer */
struct ns *ns; struct ns *ns;
}; };

View File

@ -58,6 +58,10 @@ struct zebra_router {
struct hash *ipset_entry_hash; struct hash *ipset_entry_hash;
struct hash *iptable_hash; struct hash *iptable_hash;
#if defined(HAVE_RTADV)
struct rtadv rtadv;
#endif /* HAVE_RTADV */
}; };
extern struct zebra_router zrouter; extern struct zebra_router zrouter;