summaryrefslogtreecommitdiffstats
path: root/zebra
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2019-03-27 15:05:58 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2019-06-04 18:33:57 +0200
commit9245fe61933c9ae3092d107443a418bc0e4f0c9e (patch)
treead22c51cf5f65c86bb3ccf06e7e97059491b7090 /zebra
parentzebra: move rtadv service from zrouter to zvrf (diff)
downloadfrr-9245fe61933c9ae3092d107443a418bc0e4f0c9e.tar.xz
frr-9245fe61933c9ae3092d107443a418bc0e4f0c9e.zip
zebra: keep rtadv_sock field in zrouter for optimisation
in the case the vrf backend is vrf-lite, there is no need to have separate sockets. use a socket located in zrouter, so that when needing the socket, a common API is used. that API will return the appropriate socket value. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'zebra')
-rw-r--r--zebra/rtadv.c34
-rw-r--r--zebra/zebra_router.h3
2 files changed, 28 insertions, 9 deletions
diff --git a/zebra/rtadv.c b/zebra/rtadv.c
index 80ee112a8..e181b495b 100644
--- a/zebra/rtadv.c
+++ b/zebra/rtadv.c
@@ -85,6 +85,13 @@ static void rtadv_event(struct zebra_vrf *, enum rtadv_event, int);
static int if_join_all_router(int, struct interface *);
static int if_leave_all_router(int, struct interface *);
+static int rtadv_get_socket(struct zebra_vrf *zvrf)
+{
+ if (zvrf->rtadv.sock > 0)
+ return zvrf->rtadv.sock;
+ return zrouter.rtadv_sock;
+}
+
static int rtadv_increment_received(struct zebra_vrf *zvrf, ifindex_t *ifindex)
{
int ret = -1;
@@ -499,7 +506,7 @@ static int rtadv_timer(struct thread *thread)
"Fast RA Rexmit on interface %s",
ifp->name);
- rtadv_send_packet(zvrf->rtadv.sock,
+ rtadv_send_packet(rtadv_get_socket(zvrf),
ifp);
} else {
zif->rtadv.AdvIntervalTimer -= period;
@@ -513,8 +520,8 @@ static int rtadv_timer(struct thread *thread)
zif->rtadv
.MaxRtrAdvInterval;
rtadv_send_packet(
- zvrf->rtadv.sock,
- ifp);
+ rtadv_get_socket(zvrf),
+ ifp);
}
}
}
@@ -528,7 +535,7 @@ static void rtadv_process_solicit(struct interface *ifp)
struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
assert(zvrf);
- rtadv_send_packet(zvrf->rtadv.sock, ifp);
+ rtadv_send_packet(rtadv_get_socket(zvrf), ifp);
}
/*
@@ -884,7 +891,7 @@ static void ipv6_nd_suppress_ra_set(struct interface *ifp,
zif->rtadv.AdvIntervalTimer = 0;
zvrf->rtadv.adv_if_count--;
- if_leave_all_router(zvrf->rtadv.sock, ifp);
+ if_leave_all_router(rtadv_get_socket(zvrf), ifp);
if (zvrf->rtadv.adv_if_count == 0)
rtadv_event(zvrf, RTADV_STOP, 0);
@@ -903,11 +910,11 @@ static void ipv6_nd_suppress_ra_set(struct interface *ifp,
RTADV_NUM_FAST_REXMITS;
}
- if_join_all_router(zvrf->rtadv.sock, ifp);
+ if_join_all_router(rtadv_get_socket(zvrf), ifp);
if (zvrf->rtadv.adv_if_count == 1)
rtadv_event(zvrf, RTADV_START,
- zvrf->rtadv.sock);
+ rtadv_get_socket(zvrf));
}
}
}
@@ -2140,7 +2147,14 @@ static void rtadv_event(struct zebra_vrf *zvrf, enum rtadv_event event, int val)
void rtadv_init(struct zebra_vrf *zvrf)
{
- zvrf->rtadv.sock = rtadv_make_socket(zvrf->zns->ns_id);
+ if (vrf_is_backend_netns()) {
+ zvrf->rtadv.sock = rtadv_make_socket(zvrf->zns->ns_id);
+ zrouter.rtadv_sock = -1;
+ } else if (!zrouter.rtadv_sock) {
+ zvrf->rtadv.sock = -1;
+ if (!zrouter.rtadv_sock)
+ zrouter.rtadv_sock = rtadv_make_socket(zvrf->zns->ns_id);
+ }
}
void rtadv_terminate(struct zebra_vrf *zvrf)
@@ -2149,8 +2163,10 @@ void rtadv_terminate(struct zebra_vrf *zvrf)
if (zvrf->rtadv.sock >= 0) {
close(zvrf->rtadv.sock);
zvrf->rtadv.sock = -1;
+ } else if (zrouter.rtadv_sock >= 0) {
+ close(zrouter.rtadv_sock);
+ zrouter.rtadv_sock = -1;
}
-
zvrf->rtadv.adv_if_count = 0;
zvrf->rtadv.adv_msec_if_count = 0;
}
diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h
index 7b61a6051..e50f8a118 100644
--- a/zebra/zebra_router.h
+++ b/zebra/zebra_router.h
@@ -93,6 +93,9 @@ struct zebra_router {
struct hash *iptable_hash;
+ /* used if vrf backend is not network namespace */
+ int rtadv_sock;
+
/* A sequence number used for tracking routes */
_Atomic uint32_t sequence_num;