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>
This commit is contained in:
Philippe Guibert 2019-03-27 15:05:58 +01:00
parent f20e2a09c8
commit 3738d700ff
2 changed files with 27 additions and 9 deletions

View File

@ -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_join_all_router(int, struct interface *);
static int if_leave_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) static int rtadv_increment_received(struct zebra_vrf *zvrf, ifindex_t *ifindex)
{ {
int ret = -1; int ret = -1;
@ -499,7 +506,7 @@ 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(zvrf->rtadv.sock, rtadv_send_packet(rtadv_get_socket(zvrf),
ifp); ifp);
} else { } else {
zif->rtadv.AdvIntervalTimer -= period; zif->rtadv.AdvIntervalTimer -= period;
@ -513,8 +520,8 @@ static int rtadv_timer(struct thread *thread)
zif->rtadv zif->rtadv
.MaxRtrAdvInterval; .MaxRtrAdvInterval;
rtadv_send_packet( rtadv_send_packet(
zvrf->rtadv.sock, rtadv_get_socket(zvrf),
ifp); ifp);
} }
} }
} }
@ -528,7 +535,7 @@ static void rtadv_process_solicit(struct interface *ifp)
struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
assert(zvrf); 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; zif->rtadv.AdvIntervalTimer = 0;
zvrf->rtadv.adv_if_count--; 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) if (zvrf->rtadv.adv_if_count == 0)
rtadv_event(zvrf, RTADV_STOP, 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; 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) if (zvrf->rtadv.adv_if_count == 1)
rtadv_event(zvrf, RTADV_START, rtadv_event(zvrf, RTADV_START,
zvrf->rtadv.sock); rtadv_get_socket(zvrf));
} }
} }
} }
@ -2140,7 +2147,13 @@ static void rtadv_event(struct zebra_vrf *zvrf, enum rtadv_event event, int val)
void rtadv_init(struct zebra_vrf *zvrf) 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;
zrouter.rtadv_sock = rtadv_make_socket(zvrf->zns->ns_id);
}
} }
void rtadv_terminate(struct zebra_vrf *zvrf) void rtadv_terminate(struct zebra_vrf *zvrf)
@ -2149,8 +2162,10 @@ void rtadv_terminate(struct zebra_vrf *zvrf)
if (zvrf->rtadv.sock >= 0) { if (zvrf->rtadv.sock >= 0) {
close(zvrf->rtadv.sock); close(zvrf->rtadv.sock);
zvrf->rtadv.sock = -1; 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_if_count = 0;
zvrf->rtadv.adv_msec_if_count = 0; zvrf->rtadv.adv_msec_if_count = 0;
} }

View File

@ -82,6 +82,9 @@ struct zebra_router {
struct hash *iptable_hash; struct hash *iptable_hash;
/* used if vrf backend is not network namespace */
int rtadv_sock;
/* A sequence number used for tracking routes */ /* A sequence number used for tracking routes */
_Atomic uint32_t sequence_num; _Atomic uint32_t sequence_num;