ospfd (route socket filter on priority)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ospfd (route socket filter on priority)

Sebastian Benoit-3

Hi,

here is the ospfd part again, now the socket option is set on reload as
well.

ok?

(benno_route_priofilter_2_ospfd.diff)

diff --git usr.sbin/ospfd/kroute.c usr.sbin/ospfd/kroute.c
index 17febefbdcb..4f6dc933a42 100644
--- usr.sbin/ospfd/kroute.c
+++ usr.sbin/ospfd/kroute.c
@@ -127,10 +127,11 @@ kif_init(void)
 }
 
 int
-kr_init(int fs, u_int rdomain)
+kr_init(int fs, u_int rdomain, int redis_label_or_prefix)
 {
  int opt = 0, rcvbuf, default_rcvbuf;
  socklen_t optlen;
+ int filter_prio = RTP_OSPF;
 
  kr_state.fib_sync = fs;
  kr_state.rdomain = rdomain;
@@ -146,6 +147,18 @@ kr_init(int fs, u_int rdomain)
     &opt, sizeof(opt)) == -1)
  log_warn("kr_init: setsockopt"); /* not fatal */
 
+ if (redis_label_or_prefix) {
+ filter_prio = 0;
+ log_info("%s: priority filter disabled", __func__);
+ } else
+ log_debug("%s: priority filter enabled", __func__);
+
+ if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, &filter_prio,
+    sizeof(filter_prio)) == -1) {
+ log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__);
+ /* not fatal */
+ }
+
  /* grow receive buffer, don't wanna miss messages */
  optlen = sizeof(default_rcvbuf);
  if (getsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF,
@@ -600,12 +613,27 @@ kr_redistribute(struct kroute_node *kh)
 }
 
 void
-kr_reload(void)
+kr_reload(int redis_label_or_prefix)
 {
  struct kroute_node *kr, *kn;
  u_int32_t dummy;
  int r;
+ int filter_prio = RTP_OSPF;
+
+ /* update the priority filter */
+ if (redis_label_or_prefix) {
+ filter_prio = 0;
+ log_info("%s: priority filter disabled", __func__);
+ } else
+ log_debug("%s: priority filter enabled", __func__);
+
+ if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, &filter_prio,
+    sizeof(filter_prio)) == -1) {
+ log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__);
+ /* not fatal */
+ }
 
+ /* update redistribute lists */
  RB_FOREACH(kr, kroute_tree, &krt) {
  for (kn = kr; kn; kn = kn->next) {
  r = ospf_redistribute(&kn->r, &dummy);
diff --git usr.sbin/ospfd/ospfd.c usr.sbin/ospfd/ospfd.c
index 3c5057ae04e..01fd6bbafb9 100644
--- usr.sbin/ospfd/ospfd.c
+++ usr.sbin/ospfd/ospfd.c
@@ -265,7 +265,7 @@ main(int argc, char *argv[])
  event_add(&iev_rde->ev, NULL);
 
  if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE),
-    ospfd_conf->rdomain) == -1)
+    ospfd_conf->rdomain, ospfd_conf->redist_label_or_prefix) == -1)
  fatalx("kr_init failed");
 
  /* remove unneeded stuff from config */
@@ -637,7 +637,7 @@ ospf_reload(void)
 
  merge_config(ospfd_conf, xconf);
  /* update redistribute lists */
- kr_reload();
+ kr_reload(ospfd_conf->redist_label_or_prefix);
  return (0);
 }
 
@@ -667,6 +667,7 @@ merge_config(struct ospfd_conf *conf, struct ospfd_conf *xconf)
     SIMPLEQ_EMPTY(&xconf->redist_list))
  rchange = 1;
  conf->rfc1583compat = xconf->rfc1583compat;
+ conf->redist_label_or_prefix = xconf->redist_label_or_prefix;
 
  if (ospfd_process == PROC_MAIN) {
  /* main process does neither use areas nor interfaces */
diff --git usr.sbin/ospfd/ospfd.h usr.sbin/ospfd/ospfd.h
index af082b1079c..1a5d20e0068 100644
--- usr.sbin/ospfd/ospfd.h
+++ usr.sbin/ospfd/ospfd.h
@@ -394,6 +394,7 @@ struct ospfd_conf {
  int spf_state;
  int ospf_socket;
  int flags;
+ int redist_label_or_prefix;
  u_int8_t rfc1583compat;
  u_int8_t border;
  u_int8_t redistribute;
@@ -567,7 +568,7 @@ u_int16_t iso_cksum(void *, u_int16_t, u_int16_t);
 /* kroute.c */
 int kif_init(void);
 void kif_clear(void);
-int kr_init(int, u_int);
+int kr_init(int, u_int, int);
 int kr_change(struct kroute *, int);
 int kr_delete(struct kroute *);
 void kr_shutdown(void);
@@ -578,7 +579,7 @@ void kr_dispatch_msg(int, short, void *);
 void kr_show_route(struct imsg *);
 void kr_ifinfo(char *, pid_t);
 struct kif *kif_findname(char *, struct in_addr, struct kif_addr **);
-void kr_reload(void);
+void kr_reload(int);
 
 u_int8_t mask2prefixlen(in_addr_t);
 in_addr_t prefixlen2mask(u_int8_t);
diff --git usr.sbin/ospfd/parse.y usr.sbin/ospfd/parse.y
index 4bf64d5d7e3..6f1cf5b7b19 100644
--- usr.sbin/ospfd/parse.y
+++ usr.sbin/ospfd/parse.y
@@ -295,6 +295,8 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon {
 
  if ($1)
  r->type |= REDIST_NO;
+ else
+ conf->redist_label_or_prefix = 1;
  r->metric = $6;
  if ($7)
  strlcpy(r->dependon, $7, sizeof(r->dependon));
@@ -314,9 +316,10 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon {
  r->type = REDIST_STATIC;
  else if (!strcmp($3, "connected"))
  r->type = REDIST_CONNECTED;
- else if (host($3, &r->addr, &r->mask))
+ else if (host($3, &r->addr, &r->mask)) {
  r->type = REDIST_ADDR;
- else {
+ conf->redist_label_or_prefix = (! $1);
+ } else {
  yyerror("unknown redistribute type");
  free($3);
  free(r);
@@ -343,6 +346,8 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon {
  r->label = rtlabel_name2id($4);
  if ($1)
  r->type |= REDIST_NO;
+ else
+ conf->redist_label_or_prefix = 1;
  r->metric = $5;
  if ($6)
  strlcpy(r->dependon, $6, sizeof(r->dependon));

Reply | Threaded
Open this post in threaded view
|

Re: ospfd (route socket filter on priority)

Claudio Jeker-3
On Sun, Feb 11, 2018 at 02:17:38AM +0100, Sebastian Benoit wrote:

>
> Hi,
>
> here is the ospfd part again, now the socket option is set on reload as
> well.
>
> ok?
>
> (benno_route_priofilter_2_ospfd.diff)
>
> diff --git usr.sbin/ospfd/kroute.c usr.sbin/ospfd/kroute.c
> index 17febefbdcb..4f6dc933a42 100644
> --- usr.sbin/ospfd/kroute.c
> +++ usr.sbin/ospfd/kroute.c
> @@ -127,10 +127,11 @@ kif_init(void)
>  }
>  
>  int
> -kr_init(int fs, u_int rdomain)
> +kr_init(int fs, u_int rdomain, int redis_label_or_prefix)
>  {
>   int opt = 0, rcvbuf, default_rcvbuf;
>   socklen_t optlen;
> + int filter_prio = RTP_OSPF;
>  
>   kr_state.fib_sync = fs;
>   kr_state.rdomain = rdomain;
> @@ -146,6 +147,18 @@ kr_init(int fs, u_int rdomain)
>      &opt, sizeof(opt)) == -1)
>   log_warn("kr_init: setsockopt"); /* not fatal */
>  
> + if (redis_label_or_prefix) {
> + filter_prio = 0;
> + log_info("%s: priority filter disabled", __func__);
> + } else
> + log_debug("%s: priority filter enabled", __func__);
> +
> + if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, &filter_prio,
> +    sizeof(filter_prio)) == -1) {
> + log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__);
> + /* not fatal */
> + }
> +
>   /* grow receive buffer, don't wanna miss messages */
>   optlen = sizeof(default_rcvbuf);
>   if (getsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF,
> @@ -600,12 +613,27 @@ kr_redistribute(struct kroute_node *kh)
>  }
>  
>  void
> -kr_reload(void)
> +kr_reload(int redis_label_or_prefix)
>  {
>   struct kroute_node *kr, *kn;
>   u_int32_t dummy;
>   int r;
> + int filter_prio = RTP_OSPF;
> +
> + /* update the priority filter */
> + if (redis_label_or_prefix) {
> + filter_prio = 0;
> + log_info("%s: priority filter disabled", __func__);
> + } else
> + log_debug("%s: priority filter enabled", __func__);
> +
> + if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_PRIOFILTER, &filter_prio,
> +    sizeof(filter_prio)) == -1) {
> + log_warn("%s: setsockopt AF_ROUTE ROUTE_PRIOFILTER", __func__);
> + /* not fatal */
> + }
>  
> + /* update redistribute lists */
>   RB_FOREACH(kr, kroute_tree, &krt) {
>   for (kn = kr; kn; kn = kn->next) {
>   r = ospf_redistribute(&kn->r, &dummy);
> diff --git usr.sbin/ospfd/ospfd.c usr.sbin/ospfd/ospfd.c
> index 3c5057ae04e..01fd6bbafb9 100644
> --- usr.sbin/ospfd/ospfd.c
> +++ usr.sbin/ospfd/ospfd.c
> @@ -265,7 +265,7 @@ main(int argc, char *argv[])
>   event_add(&iev_rde->ev, NULL);
>  
>   if (kr_init(!(ospfd_conf->flags & OSPFD_FLAG_NO_FIB_UPDATE),
> -    ospfd_conf->rdomain) == -1)
> +    ospfd_conf->rdomain, ospfd_conf->redist_label_or_prefix) == -1)
>   fatalx("kr_init failed");
>  
>   /* remove unneeded stuff from config */
> @@ -637,7 +637,7 @@ ospf_reload(void)
>  
>   merge_config(ospfd_conf, xconf);
>   /* update redistribute lists */
> - kr_reload();
> + kr_reload(ospfd_conf->redist_label_or_prefix);
>   return (0);
>  }
>  
> @@ -667,6 +667,7 @@ merge_config(struct ospfd_conf *conf, struct ospfd_conf *xconf)
>      SIMPLEQ_EMPTY(&xconf->redist_list))
>   rchange = 1;
>   conf->rfc1583compat = xconf->rfc1583compat;
> + conf->redist_label_or_prefix = xconf->redist_label_or_prefix;
>  
>   if (ospfd_process == PROC_MAIN) {
>   /* main process does neither use areas nor interfaces */
> diff --git usr.sbin/ospfd/ospfd.h usr.sbin/ospfd/ospfd.h
> index af082b1079c..1a5d20e0068 100644
> --- usr.sbin/ospfd/ospfd.h
> +++ usr.sbin/ospfd/ospfd.h
> @@ -394,6 +394,7 @@ struct ospfd_conf {
>   int spf_state;
>   int ospf_socket;
>   int flags;
> + int redist_label_or_prefix;
>   u_int8_t rfc1583compat;
>   u_int8_t border;
>   u_int8_t redistribute;
> @@ -567,7 +568,7 @@ u_int16_t iso_cksum(void *, u_int16_t, u_int16_t);
>  /* kroute.c */
>  int kif_init(void);
>  void kif_clear(void);
> -int kr_init(int, u_int);
> +int kr_init(int, u_int, int);
>  int kr_change(struct kroute *, int);
>  int kr_delete(struct kroute *);
>  void kr_shutdown(void);
> @@ -578,7 +579,7 @@ void kr_dispatch_msg(int, short, void *);
>  void kr_show_route(struct imsg *);
>  void kr_ifinfo(char *, pid_t);
>  struct kif *kif_findname(char *, struct in_addr, struct kif_addr **);
> -void kr_reload(void);
> +void kr_reload(int);
>  
>  u_int8_t mask2prefixlen(in_addr_t);
>  in_addr_t prefixlen2mask(u_int8_t);
> diff --git usr.sbin/ospfd/parse.y usr.sbin/ospfd/parse.y
> index 4bf64d5d7e3..6f1cf5b7b19 100644
> --- usr.sbin/ospfd/parse.y
> +++ usr.sbin/ospfd/parse.y
> @@ -295,6 +295,8 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon {
>  
>   if ($1)
>   r->type |= REDIST_NO;
> + else
> + conf->redist_label_or_prefix = 1;
>   r->metric = $6;
>   if ($7)
>   strlcpy(r->dependon, $7, sizeof(r->dependon));
> @@ -314,9 +316,10 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon {
>   r->type = REDIST_STATIC;
>   else if (!strcmp($3, "connected"))
>   r->type = REDIST_CONNECTED;
> - else if (host($3, &r->addr, &r->mask))
> + else if (host($3, &r->addr, &r->mask)) {
>   r->type = REDIST_ADDR;
> - else {
> + conf->redist_label_or_prefix = (! $1);

I think I prefer `conf->redist_label_or_prefix = !$1;` here at least that
is more KNF.

> + } else {
>   yyerror("unknown redistribute type");
>   free($3);
>   free(r);
> @@ -343,6 +346,8 @@ redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist dependon {
>   r->label = rtlabel_name2id($4);
>   if ($1)
>   r->type |= REDIST_NO;
> + else
> + conf->redist_label_or_prefix = 1;
>   r->metric = $5;
>   if ($6)
>   strlcpy(r->dependon, $6, sizeof(r->dependon));
>

Apart from that OK

--
:wq Claudio