]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
RAdv: Add custom options
authorAlexander Zubkov <green@qrator.net>
Fri, 23 Jun 2023 15:21:05 +0000 (17:21 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Fri, 23 Jun 2023 15:26:03 +0000 (17:26 +0200)
Currently one can use only a predefined set of advertised options in RAdv
protocol, which are supported by BIRD configuration. It would be convenient
to be able to specify other possible options at least manually as a blob
so one should not wait until it is supported in the code, released, etc.

This idea is inspired by presentation by OndÅ™ej Caletka at CSNOG, in which
he noticed the lack of either PREF64 option or possibility to add custom
options in various software.

The patch makes it possible to define such options with the syntax:

  other type <num> <bytestring>

proto/radv/config.Y
proto/radv/packets.c
proto/radv/radv.h

index 8d4a3ab94221bbbe0b760a0f3b479d00d0111982..5c213d505c668b242b13660874934fd18577e739 100644 (file)
@@ -25,6 +25,15 @@ static struct radv_dnssl_config this_radv_dnssl;
 static list radv_dns_list;     /* Used by radv_rdnss and radv_dnssl */
 static u8 radv_mult_val;       /* Used by radv_mult for second return value */
 
+static inline void
+radv_add_to_custom_list(list *l, int type, struct bytestring *payload)
+{
+  if (type < 0 || type > 255) cf_error("RA cusom type must be in range 0-255");
+  struct radv_custom_config *cf = cfg_allocz(sizeof(struct radv_custom_config));
+  add_tail(l, NODE cf);
+  cf->type = type;
+  cf->payload = payload;
+}
 
 CF_DECLS
 
@@ -52,6 +61,7 @@ radv_proto_start: proto_start RADV
   init_list(&RADV_CFG->pref_list);
   init_list(&RADV_CFG->rdnss_list);
   init_list(&RADV_CFG->dnssl_list);
+  init_list(&RADV_CFG->custom_list);
 };
 
 radv_proto_item:
@@ -61,6 +71,7 @@ radv_proto_item:
  | PREFIX radv_prefix { add_tail(&RADV_CFG->pref_list, NODE this_radv_prefix); }
  | RDNSS { init_list(&radv_dns_list); } radv_rdnss { add_tail_list(&RADV_CFG->rdnss_list, &radv_dns_list); }
  | DNSSL { init_list(&radv_dns_list); } radv_dnssl { add_tail_list(&RADV_CFG->dnssl_list, &radv_dns_list); }
+ | OTHER TYPE expr BYTESTRING { radv_add_to_custom_list(&RADV_CFG->custom_list, $3, $4); }
  | TRIGGER net_ip6 { RADV_CFG->trigger = $2; }
  | PROPAGATE ROUTES bool { RADV_CFG->propagate_routes = $3; }
  ;
@@ -82,6 +93,7 @@ radv_iface_start:
   init_list(&RADV_IFACE->pref_list);
   init_list(&RADV_IFACE->rdnss_list);
   init_list(&RADV_IFACE->dnssl_list);
+  init_list(&RADV_IFACE->custom_list);
 
   RADV_IFACE->min_ra_int = (u32) -1; /* undefined */
   RADV_IFACE->max_ra_int = DEFAULT_MAX_RA_INT;
@@ -124,8 +136,10 @@ radv_iface_item:
  | PREFIX radv_prefix { add_tail(&RADV_IFACE->pref_list, NODE this_radv_prefix); }
  | RDNSS { init_list(&radv_dns_list); } radv_rdnss { add_tail_list(&RADV_IFACE->rdnss_list, &radv_dns_list); }
  | DNSSL { init_list(&radv_dns_list); } radv_dnssl { add_tail_list(&RADV_IFACE->dnssl_list, &radv_dns_list); }
+ | OTHER TYPE expr BYTESTRING { radv_add_to_custom_list(&RADV_IFACE->custom_list, $3, $4); }
  | RDNSS LOCAL bool { RADV_IFACE->rdnss_local = $3; }
  | DNSSL LOCAL bool { RADV_IFACE->dnssl_local = $3; }
+ | OTHER LOCAL bool { RADV_IFACE->custom_local = $3; }
  ;
 
 radv_preference:
index 5cd8b2deb9c0a90f51a0d5e5d5e10326d93fe18b..d1f86ec1718bc4824c16b959c76865efeddd1a10 100644 (file)
@@ -82,6 +82,13 @@ struct radv_opt_dnssl
   char domain[];
 };
 
+struct radv_opt_custom
+{
+  u8 type;
+  u8 length;
+  u8 payload[];
+};
+
 static int
 radv_prepare_route(struct radv_iface *ifa, struct radv_route *rt,
                   char **buf, char *bufend)
@@ -254,6 +261,36 @@ radv_prepare_dnssl(struct radv_iface *ifa, list *dnssl_list, char **buf, char *b
   return -1;
 }
 
+static int
+radv_prepare_custom(struct radv_iface *ifa, list *custom_list, char **buf, char *bufend)
+{
+  struct radv_custom_config *ccf = HEAD(*custom_list);
+
+  while(NODE_VALID(ccf))
+  {
+    struct radv_opt_custom *op = (void *) *buf;
+    /* Add 2 octets for type and size and 8 - 1 for ceiling the division up to 8 octets */
+    int size = (ccf->payload->length + 2 + 8 - 1) / 8;
+    if (bufend - *buf < size * 8)
+      goto too_much;
+
+    memset(op, 0, size * 8); /* Clear buffer so there is no tail garbage */
+    op->type = ccf->type;
+    op->length = size;
+    memcpy(op->payload, ccf->payload->data, ccf->payload->length);
+
+    *buf += 8 * op->length;
+    ccf = NODE_NEXT(ccf);
+  }
+
+  return 0;
+
+ too_much:
+  log(L_WARN "%s: Too many RA options on interface %s",
+      ifa->ra->p.name, ifa->iface->name);
+  return -1;
+}
+
 static int
 radv_prepare_prefix(struct radv_iface *ifa, struct radv_prefix *px,
                    char **buf, char *bufend)
@@ -352,6 +389,14 @@ radv_prepare_ra(struct radv_iface *ifa)
   if (radv_prepare_dnssl(ifa, &ic->dnssl_list, &buf, bufend) < 0)
     goto done;
 
+  if (! ic->custom_local)
+    if (radv_prepare_custom(ifa, &cf->custom_list, &buf, bufend) < 0)
+      goto done;
+
+  if (radv_prepare_custom(ifa, &ic->custom_list, &buf, bufend) < 0)
+    goto done;
+
+
   if (p->fib_up)
   {
     FIB_WALK(&p->routes, struct radv_route, rt)
index 14d40f8abca285c0a86232103e1059f8daba0e08..8c7161582eb039c8ce0064ea5f16686bfd843049 100644 (file)
@@ -51,6 +51,7 @@ struct radv_config
   list pref_list;              /* Global list of prefix configs (struct radv_prefix_config) */
   list rdnss_list;             /* Global list of RDNSS configs (struct radv_rdnss_config) */
   list dnssl_list;             /* Global list of DNSSL configs (struct radv_dnssl_config) */
+  list custom_list;            /* Global list of custom configs (struct radv_custom_config) */
 
   net_addr trigger;            /* Prefix of a trigger route, if defined */
   u8 propagate_routes;         /* Do we propagate more specific routes (RFC 4191)? */
@@ -63,6 +64,7 @@ struct radv_iface_config
   list pref_list;              /* Local list of prefix configs (struct radv_prefix_config) */
   list rdnss_list;             /* Local list of RDNSS configs (struct radv_rdnss_config) */
   list dnssl_list;             /* Local list of DNSSL configs (struct radv_dnssl_config) */
+  list custom_list;            /* Local list of custom configs (struct radv_custom_config) */
 
   u32 min_ra_int;              /* Standard options from RFC 4861 */
   u32 max_ra_int;
@@ -75,6 +77,7 @@ struct radv_iface_config
 
   u8 rdnss_local;              /* Global list is not used for RDNSS */
   u8 dnssl_local;              /* Global list is not used for DNSSL */
+  u8 custom_local;             /* Global list is not used for custom */
 
   u8 managed;                  /* Standard options from RFC 4861 */
   u8 other_config;
@@ -122,6 +125,13 @@ struct radv_dnssl_config
   const char *domain;          /* Domain for DNS search list, in processed form */
 };
 
+struct radv_custom_config
+{
+  node n;
+  u8 type;                     /* Identifier of the type of option */
+  struct bytestring *payload;  /* Payload of the option */
+};
+
 /*
  * One more specific route as per RFC 4191.
  *