0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 02:01:55 +00:00

Filter: Make ifname attribute modifiable

Allow to change an interface associated with a route by setting
ifname attribute. It will also change the route to a direct one.
This commit is contained in:
Ondrej Zajicek (work) 2018-11-05 21:55:18 +01:00
parent fff79b1c1e
commit 716b904f4e
4 changed files with 21 additions and 5 deletions

View File

@ -1405,7 +1405,8 @@ clist for most purposes.
<tag><label id="rta-ifname"><m/string/ ifname</tag> <tag><label id="rta-ifname"><m/string/ ifname</tag>
Name of the outgoing interface. Sink routes (like blackhole, unreachable Name of the outgoing interface. Sink routes (like blackhole, unreachable
or prohibit) and multipath routes have no interface associated with or prohibit) and multipath routes have no interface associated with
them, so <cf/ifname/ returns an empty string for such routes. Read-only. them, so <cf/ifname/ returns an empty string for such routes. Setting it
would also change route to a direct one (remove gateway).
<tag><label id="rta-ifindex"><m/int/ ifindex</tag> <tag><label id="rta-ifindex"><m/int/ ifindex</tag>
Index of the outgoing interface. System wide index of the interface. May Index of the outgoing interface. System wide index of the interface. May

View File

@ -792,7 +792,7 @@ static_attr:
| SCOPE { $$ = f_new_static_attr(T_ENUM_SCOPE, SA_SCOPE, 1); } | SCOPE { $$ = f_new_static_attr(T_ENUM_SCOPE, SA_SCOPE, 1); }
| CAST { $$ = f_new_static_attr(T_ENUM_RTC, SA_CAST, 0); } | CAST { $$ = f_new_static_attr(T_ENUM_RTC, SA_CAST, 0); }
| DEST { $$ = f_new_static_attr(T_ENUM_RTD, SA_DEST, 1); } | DEST { $$ = f_new_static_attr(T_ENUM_RTD, SA_DEST, 1); }
| IFNAME { $$ = f_new_static_attr(T_STRING, SA_IFNAME, 0); } | IFNAME { $$ = f_new_static_attr(T_STRING, SA_IFNAME, 1); }
| IFINDEX { $$ = f_new_static_attr(T_INT, SA_IFINDEX, 0); } | IFINDEX { $$ = f_new_static_attr(T_INT, SA_IFINDEX, 0); }
; ;

View File

@ -1000,6 +1000,20 @@ interpret(struct f_inst *what)
rta->hostentry = NULL; rta->hostentry = NULL;
break; break;
case SA_IFNAME:
{
struct iface *ifa = if_find_by_name(v1.val.s);
if (!ifa)
runtime( "Invalid iface name" );
rta->dest = RTD_DEVICE;
rta->gw = IPA_NONE;
rta->iface = ifa;
rta->nexthops = NULL;
rta->hostentry = NULL;
}
break;
default: default:
bug("Invalid static attribute access (%x)", res.type); bug("Invalid static attribute access (%x)", res.type);
} }

View File

@ -441,7 +441,7 @@ if_find_by_name(char *name)
struct iface *i; struct iface *i;
WALK_LIST(i, iface_list) WALK_LIST(i, iface_list)
if (!strcmp(i->name, name)) if (!strcmp(i->name, name) && !(i->flags & IF_SHUTDOWN))
return i; return i;
return NULL; return NULL;
} }
@ -451,7 +451,8 @@ if_get_by_name(char *name)
{ {
struct iface *i; struct iface *i;
if (i = if_find_by_name(name)) WALK_LIST(i, iface_list)
if (!strcmp(i->name, name))
return i; return i;
/* No active iface, create a dummy */ /* No active iface, create a dummy */