Commit f2010f9c authored by Jan Moskyto Matejka's avatar Jan Moskyto Matejka

Static: Protocol rework wrt. struct nexthop changes; MPLS label support

parent 33ad6e01
......@@ -64,6 +64,7 @@ CF_DECLS
struct proto_spec ps;
struct channel_limit cl;
struct timeformat *tf;
u32 *lbl;
}
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
......@@ -82,6 +83,7 @@ CF_DECLS
%type <a> ipa
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
%type <net_ptr> net_ net_any net_roa4_ net_roa6_ net_roa_
%type <lbl> label_stack_start label_stack
%type <t> text opttext
......@@ -266,6 +268,22 @@ net_or_ipa:
}
;
label_stack_start: NUM
{
$$ = cfg_allocz(sizeof(u32) * (NEXTHOP_MAX_LABEL_STACK+1));
$$[0] = 1;
$$[1] = $1;
};
label_stack:
label_stack_start
| label_stack '/' NUM {
if ($1[0] >= NEXTHOP_MAX_LABEL_STACK)
cf_error("Too many labels in stack.");
$1[++$1[0]] = $3;
$$ = $1;
}
;
datetime:
TEXT {
......
......@@ -4141,8 +4141,8 @@ specific destination for them and you don't want to send them out through the
default route to prevent routing loops).
<p>There are five types of static routes: `classical' routes telling to forward
packets to a neighboring router, multipath routes specifying several (possibly
weighted) neighboring routers, device routes specifying forwarding to hosts on a
packets to a neighboring router (single path or multipath, possibly weighted),
device routes specifying forwarding to hosts on a
directly connected network, recursive routes computing their nexthops by doing
route table lookups for a given IP, and special routes (sink, blackhole etc.)
which specify a special action to be done instead of forwarding the packet.
......@@ -4174,14 +4174,14 @@ definition of the protocol contains mainly a list of static routes.
<p>Route definitions (each may also contain a block of per-route options):
<descrip>
<tag><label id="static-route-via-ip">route <m/prefix/ via <m/ip/</tag>
Static route through a neighboring router. For link-local next hops,
<tag><label id="static-route-via-ip">route <m/prefix/ via <m/ip/ [mpls <m/num/[/<m/num/[/<m/num/[...]]]]</tag>
Static single path route through a neighboring router. For link-local next hops,
interface can be specified as a part of the address (e.g.,
<cf/via fe80::1234%eth0/).
<cf/via fe80::1234%eth0/). MPLS labels should be specified in outer-first order.
<tag><label id="static-route-via-mpath">route <m/prefix/ multipath via <m/ip/ [weight <m/num/] [bfd <m/switch/] [via <m/.../]</tag>
<tag><label id="static-route-via-mpath">route <m/prefix/ via <m/ip/ [mpls <m/num/[/<m/num/[/<m/num/[...]]]] [weight <m/num/] [bfd <m/switch/] [via ...]</tag>
Static multipath route. Contains several nexthops (gateways), possibly
with their weights.
with their weights and MPLS labels.
<tag><label id="static-route-via-iface">route <m/prefix/ via <m/"interface"/</tag>
Static device route through an interface to hosts on a directly
......
......@@ -513,6 +513,7 @@ ea_list *ea_append(ea_list *to, ea_list *what);
void ea_format_bitfield(struct eattr *a, byte *buf, int bufsize, const char **names, int min, int max);
#define NEXTHOP_MAX_LABEL_STACK 8
#define NEXTHOP_MAX_SIZE (sizeof(struct nexthop) + sizeof(u32)*NEXTHOP_MAX_LABEL_STACK)
static inline size_t nexthop_size(const struct nexthop *nh)
{ return sizeof(struct nexthop) + sizeof(u32)*nh->labels; }
......@@ -527,6 +528,7 @@ int nexthop_is_sorted(struct nexthop *x);
void rta_init(void);
static inline size_t rta_size(const rta *a) { return sizeof(rta) + sizeof(u32)*a->nh.labels; }
#define RTA_MAX_SIZE (sizeof(rta) + sizeof(u32)*NEXTHOP_MAX_LABEL_STACK)
rta *rta_lookup(rta *); /* Get rta equivalent to this one, uc++ */
static inline int rta_is_cached(rta *r) { return r->aflags & RTAF_CACHED; }
static inline rta *rta_clone(rta *r) { r->uc++; return r; }
......
......@@ -330,6 +330,9 @@ nexthop_copy(struct nexthop *o)
n->iface = o->iface;
n->next = NULL;
n->weight = o->weight;
n->labels = o->labels;
for (int i=0; i<o->labels; i++)
n->label[i] = o->label[i];
*last = n;
last = &(n->next);
......@@ -1176,6 +1179,12 @@ rta_do_cow(rta *o, linpool *lp)
{
rta *r = lp_alloc(lp, rta_size(o));
memcpy(r, o, rta_size(o));
for (struct nexthop **nhn = &(r->nh.next), *nho = o->nh.next; nho; nho = nho->next)
{
*nhn = lp_alloc(lp, nexthop_size(nho));
memcpy(*nhn, nho, nexthop_size(nho));
nhn = &((*nhn)->next);
}
r->aflags = 0;
r->uc = 0;
return r;
......
......@@ -2443,14 +2443,7 @@ rt_format_via(rte *e)
switch (a->dest)
{
case RTD_UNICAST: if (a->nh.next)
bsprintf(via, "multipath");
else
{
if (ipa_nonzero(a->nh.gw)) bsprintf(via, "via %I ", a->nh.gw);
bsprintf(via, "dev %s", a->nh.iface->name);
}
break;
case RTD_UNICAST: bsprintf(via, "unicast"); break;
case RTD_BLACKHOLE: bsprintf(via, "blackhole"); break;
case RTD_UNREACHABLE: bsprintf(via, "unreachable"); break;
case RTD_PROHIBIT: bsprintf(via, "prohibited"); break;
......@@ -2492,11 +2485,24 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, ea_list *tm
bsprintf(info, " (%d)", e->pref);
cli_printf(c, -1007, "%-18s %s [%s %s%s]%s%s", ia, rt_format_via(e), a->src->proto->name,
tm, from, primary ? (sync_error ? " !" : " *") : "", info);
if (a->nh.next)
for (nh = &(a->nh); nh; nh = nh->next)
cli_printf(c, -1007, "\tvia %I on %s weight %d", nh->gw, nh->iface->name, nh->weight + 1);
for (nh = &(a->nh); nh; nh = nh->next)
{
char ls[NEXTHOP_MAX_LABEL_STACK*8 + 5]; char *lsp = ls;
if (nh->labels)
{
lsp += bsprintf(lsp, " mpls %d", nh->label[0]);
for (int i=1;i<nh->labels; i++)
lsp += bsprintf(lsp, "/%d", nh->label[i]);
*lsp++ = '\0';
}
if (a->nh.next)
cli_printf(c, -1007, "\tvia %I%s on %s weight %d", nh->gw, (nh->labels ? ls : ""), nh->iface->name, nh->weight + 1);
else
cli_printf(c, -1007, "\tvia %I%s on %s", nh->gw, (nh->labels ? ls : ""), nh->iface->name);
}
if (d->verbose)
rta_show(c, a, tmpa);
}
static void
......
......@@ -18,19 +18,12 @@ static struct f_inst **this_srt_last_cmd;
static void
static_route_finish(void)
{
struct static_route *r;
/* Update undefined use_bfd entries in multipath nexthops */
for (r = this_srt->mp_next; r; r = r->mp_next)
if (r->use_bfd < 0)
r->use_bfd = this_srt->use_bfd;
}
{ }
CF_DECLS
CF_KEYWORDS(STATIC, ROUTE, VIA, DROP, REJECT, PROHIBIT, PREFERENCE, CHECK, LINK)
CF_KEYWORDS(MULTIPATH, WEIGHT, RECURSIVE, IGP, TABLE, BLACKHOLE, UNREACHABLE, BFD)
CF_KEYWORDS(WEIGHT, RECURSIVE, IGP, TABLE, BLACKHOLE, UNREACHABLE, BFD, MPLS)
CF_GRAMMAR
......@@ -52,6 +45,50 @@ static_proto:
| static_proto stat_route stat_route_opt_list ';' { static_route_finish(); }
;
stat_nexthop_via: VIA
{
if (last_srt)
{
last_srt = (last_srt->mp_next = cfg_allocz(sizeof(struct static_route)));
last_srt->net = this_srt->net;
}
else
{
last_srt = this_srt;
rem_node(&this_srt->n);
}
last_srt->mp_head = this_srt;
last_srt->dest = RTD_UNICAST;
};
stat_nexthop_ident:
stat_nexthop_via ipa ipa_scope {
last_srt->via = $2;
last_srt->iface = $3;
add_tail(&STATIC_CFG->neigh_routes, &last_srt->n);
}
| stat_nexthop_via TEXT {
last_srt->via = IPA_NONE;
last_srt->if_name = $2;
add_tail(&STATIC_CFG->iface_routes, &last_srt->n);
}
| stat_nexthop_ident MPLS label_stack {
last_srt->label_count = $3[0];
last_srt->label_stack = &($3[1]);
}
| stat_nexthop_ident WEIGHT expr {
last_srt->weight = $3 - 1;
if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256");
}
| stat_nexthop_ident BFD bool { last_srt->use_bfd = $3; cf_check_bfd($3); }
;
stat_nexthop:
stat_nexthop_ident
| stat_nexthop stat_nexthop_ident
;
stat_route0: ROUTE net_any {
this_srt = cfg_allocz(sizeof(struct static_route));
add_tail(&STATIC_CFG->other_routes, &this_srt->n);
......@@ -62,45 +99,8 @@ stat_route0: ROUTE net_any {
}
;
stat_multipath1:
VIA ipa ipa_scope {
last_srt = last_srt ? last_srt->mp_next = cfg_allocz(sizeof(struct static_route)) : this_srt;
last_srt->dest = RTD_UNICAST;
last_srt->via = $2;
last_srt->via_if = $3;
last_srt->if_name = (void *) this_srt; /* really */
last_srt->use_bfd = -1; /* undefined */
last_srt->mp_next = NULL;
}
| stat_multipath1 WEIGHT expr {
last_srt->weight = $3 - 1;
if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256");
}
| stat_multipath1 BFD bool {
last_srt->use_bfd = $3; cf_check_bfd($3);
}
;
stat_multipath:
stat_multipath1
| stat_multipath stat_multipath1
;
stat_route:
stat_route0 VIA ipa ipa_scope {
this_srt->dest = RTD_UNICAST;
this_srt->via = $3;
this_srt->via_if = $4;
}
| stat_route0 VIA TEXT {
this_srt->dest = RTD_UNICAST;
this_srt->via = IPA_NONE;
this_srt->if_name = $3;
rem_node(&this_srt->n);
add_tail(&STATIC_CFG->iface_routes, &this_srt->n);
}
| stat_route0 MULTIPATH stat_multipath
stat_route0 stat_nexthop
| stat_route0 RECURSIVE ipa {
this_srt->dest = RTDX_RECURSIVE;
this_srt->via = $3;
......@@ -115,7 +115,6 @@ stat_route:
stat_route_item:
cmd { *this_srt_last_cmd = $1; this_srt_last_cmd = &($1->next); }
| BFD bool ';' { this_srt->use_bfd = $2; cf_check_bfd($2); }
;
stat_route_opts:
......
This diff is collapsed.
......@@ -15,7 +15,8 @@
struct static_config {
struct proto_config c;
list iface_routes; /* Routes to search on interface events */
list other_routes; /* Routes hooked to neighbor cache and reject routes */
list neigh_routes; /* Routes to search on neighbor events */
list other_routes; /* Non-nexthop routes */
int check_link; /* Whether iface link state is used */
struct rtable_config *igp_table; /* Table used for recursive next hop lookups */
};
......@@ -29,21 +30,23 @@ struct static_route {
net_addr *net; /* Network we route */
int dest; /* Destination type (RTD_*) */
ip_addr via; /* Destination router */
struct iface *via_if; /* Destination iface, for link-local vias */
struct iface *iface; /* Destination iface, for link-local vias or device routes */
struct neighbor *neigh;
byte *if_name; /* Name for RTD_DEVICE routes */
byte *if_name; /* Name for device routes */
struct static_route *mp_next; /* Nexthops for multipath routes */
struct static_route *mp_head; /* First nexthop of this route */
struct f_inst *cmds; /* List of commands for setting attributes */
u32 state; /* Current state: STS_* */
int use_bfd; /* Configured to use BFD */
int weight; /* Multipath next hop weight */
byte use_bfd; /* Configured to use BFD */
byte label_count; /* Number of labels in stack */
struct bfd_request *bfd_req; /* BFD request, if BFD is used */
u32 *label_stack; /* Label stack if label_count > 0 */
};
#define STS_INSTALLED 0x1
#define STS_INSTALLED_ANY 0x2
#define STS_WANT 0x4
#define STS_FORCE 0x8
#define STS_WANT 0x2
#define STS_FORCE 0x4
/* Dummy nodes (parts of multipath route) abuses masklen field for weight
and if_name field for a ptr to the master (RTD_MULTIPATH) node. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment