Skip to content

Commit

Permalink
infix-vlan: Create a custom vlan model
Browse files Browse the repository at this point in the history
This implements the new model infix-if-vlan.
The new CLI is:

root@infix-00-00-00:/config/interfaces/interface/vlan10/> set vlan id 10 lower-layer-if eth0

with an possible extra option for tag-type, default tag-type is c-vlan.
  • Loading branch information
mattiaswal committed Oct 27, 2023
1 parent be8bad9 commit b7bf421
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 615 deletions.
13 changes: 8 additions & 5 deletions board/netconf/rootfs/lib/infix/cli-pretty
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class Iface:
self.in_octets = ''
self.out_octets = ''

self.parent = data.get('ietf-if-extensions:parent-interface', None)

if self.data.get('ietf-ip:ipv4'):
self.mtu = self.data.get('ietf-ip:ipv4').get('mtu', '')
self.ipv4_addr = self.data.get('ietf-ip:ipv4').get('address', '')
Expand All @@ -75,6 +73,11 @@ class Iface:
else:
self.bridge = ''

if self.data.get('infix-interfaces:vlan'):
self.lower_if = self.data.get('infix-interfaces:vlan', None).get('lower-layer-if',None)
else:
self.lower_if = ''

def is_vlan(self):
return self.data['type'] == "infix-if-type:vlan"

Expand Down Expand Up @@ -136,15 +139,15 @@ class Iface:
self.pr_name(pipe="")
self.pr_proto_eth()

if self.parent:
if self.lower_if:
self.pr_proto_ipv4(pipe='│')
self.pr_proto_ipv6(pipe='│')
else:
self.pr_proto_ipv4()
self.pr_proto_ipv6()
return

parent = find_iface(_ifaces, self.parent)
parent = find_iface(_ifaces, self.lower_if)
if not parent:
print(f"Error, didn't find parent interface for vlan {self.name}")
sys.exit(1)
Expand Down Expand Up @@ -227,7 +230,7 @@ def pr_interface_list(json):
continue

# These interfaces are printed by there parent, such as bridge
if iface.parent:
if iface.lower_if:
continue
if iface.bridge:
continue
Expand Down
4 changes: 0 additions & 4 deletions src/confd/bin/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ sysrepoctl -s $SEARCH \
-i [email protected] -g wheel -p 0660 \
-e on-change \
-i [email protected] -g wheel -p 0660 \
-i [email protected] -g wheel -p 0660 \
-e sub-interfaces \
-i [email protected] -g wheel -p 0660 \
-i [email protected] \
-g wheel -p 0660 \
-i [email protected] -g wheel -p 0660 \
-i [email protected] -g wheel -p 0660 \
-i [email protected] -g wheel -p 0660 \
Expand Down
83 changes: 33 additions & 50 deletions src/confd/src/ietf-interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,43 +168,37 @@ static int ifchange_cand_infer_vlan(sr_session_ctx_t *session, const char *path)
goto out_free_ifname;

err = srx_nitems(session, &cnt,
"%s/ietf-if-extensions:parent-interface", xpath);
"%s/infix-if-vlan:vlan"
"/lower-layer-if", xpath);
if (!err && !cnt) {
inferred.data.string_val = ifname;
err = srx_set_item(session, &inferred, 0,
"%s/ietf-if-extensions:parent-interface", xpath);
"%s/infix-if-vlan:vlan"
"/lower-layer-if", xpath);
if (err)
goto out_free_ifname;
}

err = srx_nitems(session, &cnt,
"%s"
"/ietf-if-extensions:encapsulation"
"/ietf-if-vlan-encapsulation:dot1q-vlan"
"/outer-tag/tag-type", xpath);
"%s/infix-if-vlan:vlan"
"/tag-type", xpath);
if (!err && !cnt) {
inferred.data.string_val = "ieee802-dot1q-types:c-vlan";
err = srx_set_item(session, &inferred, 0,
"%s"
"/ietf-if-extensions:encapsulation"
"/ietf-if-vlan-encapsulation:dot1q-vlan"
"/outer-tag/tag-type", xpath);
"%s/infix-if-vlan:vlan"
"/tag-type", xpath);
if (err)
goto out_free_ifname;
}

err = srx_nitems(session, &cnt,
"%s"
"/ietf-if-extensions:encapsulation"
"/ietf-if-vlan-encapsulation:dot1q-vlan"
"/outer-tag/vlan-id", xpath);
"%s/infix-if-vlan:vlan"
"/id", xpath);
if (!err && !cnt) {
inferred.data.string_val = vidstr;
err = srx_set_item(session, &inferred, 0,
"%s"
"/ietf-if-extensions:encapsulation"
"/ietf-if-vlan-encapsulation:dot1q-vlan"
"/outer-tag/vlan-id", xpath);
"%s/infix-if-vlan:vlan"
"/id", xpath);
if (err)
goto out_free_ifname;
}
Expand Down Expand Up @@ -891,46 +885,44 @@ static int netdag_gen_veth(struct dagger *net, struct lyd_node *dif,
static int netdag_gen_vlan(struct dagger *net, struct lyd_node *dif,
struct lyd_node *cif, FILE *ip)
{
const char *parent = lydx_get_cattr(cif, "parent-interface");
const char *ifname = lydx_get_cattr(cif, "name");
struct lydx_diff typed, vidd;
struct lyd_node *otag;
struct lyd_node *vlan;
const char *lower_if;
const char *proto;
int err;

DEBUG("ifname %s parent %s", ifname, parent);

err = dagger_add_dep(net, ifname, parent);
if (err)
return ERR_IFACE(cif, err, "Unable to add dep \"%s\"", parent);

otag = lydx_get_descendant(lyd_child(dif ? : cif),
"encapsulation",
"dot1q-vlan",
"outer-tag",
NULL);
if (!otag) {
vlan = lydx_get_descendant(lyd_child(dif ? : cif), "vlan", NULL);
if (!vlan) {
/*
* Note: this is only an error if outer-tag is missing
* Note: this is only an error if vlan subcontext is missing
* from cif, otherwise it just means the interface had a
* a change that was not related to the VLAN config.
*/
if (!dif)
ERROR("%s: missing mandatory outer-tag", ifname);
ERROR("%s: missing mandatory vlan", ifname);
return 0;
}

lower_if = lydx_get_cattr(vlan, "lower-layer-if");
DEBUG("ifname %s lower if %s\n", ifname, lower_if);

err = dagger_add_dep(net, ifname, lower_if);
if (err)
return ERR_IFACE(cif, err, "Unable to add dep \"%s\"", lower_if);

fprintf(ip, "link add dev %s down link %s type vlan", ifname, parent);

if (lydx_get_diff(lydx_get_child(otag, "tag-type"), &typed)) {
fprintf(ip, "link add dev %s down link %s type vlan", ifname, lower_if);

if (lydx_get_diff(lydx_get_child(vlan, "tag-type"), &typed)) {
proto = bridge_tagtype2str(typed.new);
if (!proto)
return ERR_IFACE(cif, -ENOSYS, "Unsupported tag type \"%s\"", typed.new);

fprintf(ip, " proto %s", proto);
}

if (lydx_get_diff(lydx_get_child(otag, "vlan-id"), &vidd))
if (lydx_get_diff(lydx_get_child(vlan, "id"), &vidd))
fprintf(ip, " id %s", vidd.new);

fputc('\n', ip);
Expand Down Expand Up @@ -996,24 +988,15 @@ static bool netdag_must_del(struct lyd_node *dif, struct lyd_node *cif)
{
const char *iftype = lydx_get_cattr(cif, "type");

if (!strcmp(iftype, "infix-if-type:bridge")) {
if (is_phys_addr_deleted(dif))
return true;
} else if (!strcmp(iftype, "infix-if-type:vlan")) {
if (strcmp(iftype, "infix-if-type:ethernet")) {
if (is_phys_addr_deleted(dif))
return true;
}

if (lydx_get_cattr(dif, "parent-interface") ||
lydx_get_descendant(lyd_child(dif),
"encapsulation",
"dot1q-vlan",
"outer-tag",
NULL))
if (!strcmp(iftype, "infix-if-type:vlan")) {
if (lydx_get_descendant(lyd_child(dif), "vlan", NULL))
return true;
} else if (!strcmp(iftype, "infix-if-type:veth")) {
if (is_phys_addr_deleted(dif))
return true;

if (lydx_get_descendant(lyd_child(dif), "peer", NULL))
return true;
/*
Expand Down
Loading

0 comments on commit b7bf421

Please sign in to comment.