confd: add deviation for if:type limiting it to supported types

This patch adds a new infix-interface-type, derived from the IANA base
type, allowing us to limit the list of supported native interface types.

Basing on IANA interface type ensure compatibility with other models,
e.g., standard/ieee/published/802.3/ieee802-ethernet-interface.yang,
which attaches itself to all interfaces of type ianaift:ethernetCsmacd.

Tested with yanglint and in Infix using ieee802-ethernet-interface.yang,
the 'ethernet' container was properly attached to interfaces of type
infixift:ethernet.

Tab completion in the CLI now lists only the supported types.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-08-22 13:32:47 +02:00
committed by Tobias Waldekranz
parent 43dd052707
commit 34fd50d1b8
7 changed files with 113 additions and 52 deletions
@@ -7,7 +7,7 @@ gen_interface()
cat <<EOF
,{
"name": "$1",
"type": "iana-if-type:ethernetCsmacd",
"type": "infix-if-type:ethernet",
"ietf-ip:ipv6": {
"enabled": true
}
@@ -27,7 +27,7 @@ cat <<EOF
"interface": [
{
"name": "lo",
"type": "iana-if-type:softwareLoopback",
"type": "infix-if-type:loopback",
"ietf-ip:ipv4": {
"address": [{ "ip": "127.0.0.1", "prefix-length": 8 }]
},
+12 -12
View File
@@ -142,7 +142,7 @@ static int ifchange_cand_infer_vlan(sr_session_ctx_t *session, const char *path)
type = srx_get_str(session, "%s/type", xpath);
if (!type)
goto out;
if (strcmp(type, "iana-if-type:l2vlan"))
if (strcmp(type, "infix-if-type:vlan"))
goto out_free_type;
ifname = srx_get_str(session, "%s/name", xpath);
@@ -240,17 +240,17 @@ static int ifchange_cand_infer_type(sr_session_ctx_t *session, const char *path)
}
if (iface_is_phys(ifname))
inferred.data.string_val = "iana-if-type:ethernetCsmacd";
inferred.data.string_val = "infix-if-type:ethernet";
else if (!fnmatch("br+([0-9])", ifname, FNM_EXTMATCH))
inferred.data.string_val = "iana-if-type:bridge";
inferred.data.string_val = "infix-if-type:bridge";
else if (!fnmatch("lag+([0-9])", ifname, FNM_EXTMATCH))
inferred.data.string_val = "iana-if-type:ieee8023adLag";
inferred.data.string_val = "infix-if-type:lag";
else if (!fnmatch("veth+([0-9a-z_-])", ifname, FNM_EXTMATCH))
inferred.data.string_val = "infix-if-type:veth";
else if (!fnmatch("vlan+([0-9])", ifname, FNM_EXTMATCH))
inferred.data.string_val = "iana-if-type:l2vlan";
inferred.data.string_val = "infix-if-type:vlan";
else if (!fnmatch("*.+([0-9])", ifname, FNM_EXTMATCH))
inferred.data.string_val = "iana-if-type:l2vlan";
inferred.data.string_val = "infix-if-type:vlan";
free(ifname);
@@ -856,11 +856,11 @@ static int netdag_gen_afspec_add(struct dagger *net, struct lyd_node *dif,
DEBUG_IFACE(dif, "");
if (!strcmp(iftype, "iana-if-type:bridge")) {
if (!strcmp(iftype, "infix-if-type:bridge")) {
err = netdag_gen_bridge(net, dif, cif, ip, 1);
} else if (!strcmp(iftype, "infix-if-type:veth")) {
err = netdag_gen_veth(net, NULL, cif, ip);
} else if (!strcmp(iftype, "iana-if-type:l2vlan")) {
} else if (!strcmp(iftype, "infix-if-type:vlan")) {
err = netdag_gen_vlan(net, NULL, cif, ip);
} else {
ERROR("unsupported interface type \"%s\"", iftype);
@@ -880,9 +880,9 @@ static int netdag_gen_afspec_set(struct dagger *net, struct lyd_node *dif,
DEBUG_IFACE(dif, "");
if (!strcmp(iftype, "iana-if-type:bridge"))
if (!strcmp(iftype, "infix-if-type:bridge"))
return netdag_gen_bridge(net, dif, cif, ip, 0);
if (!strcmp(iftype, "iana-if-type:l2vlan"))
if (!strcmp(iftype, "infix-if-type:vlan"))
return netdag_gen_vlan(net, dif, cif, ip);
if (!strcmp(iftype, "infix-if-type:veth"))
return 0;
@@ -895,9 +895,9 @@ static bool netdag_must_del(struct lyd_node *dif, struct lyd_node *cif)
{
const char *iftype = lydx_get_cattr(cif, "type");
if (!strcmp(iftype, "iana-if-type:bridge"))
if (!strcmp(iftype, "infix-if-type:bridge"))
return 0;
if (!strcmp(iftype, "iana-if-type:l2vlan"))
if (!strcmp(iftype, "infix-if-type:vlan"))
return lydx_get_cattr(dif, "parent-interface") ||
lydx_get_descendant(lyd_child(dif),
"encapsulation",
+2 -2
View File
@@ -76,8 +76,8 @@ sysrepoctl -s $SEARCH \
-i ietf-if-vlan-encapsulation@2023-01-26.yang \
-g wheel -p 0660 \
-i infix-ip@2023-04-24.yang -g wheel -p 0660 \
-i infix-if-type@2023-06-09.yang -g wheel -p 0660 \
-i infix-interfaces@2023-06-05.yang -g wheel -p 0660 \
-i infix-if-type@2023-08-21.yang -g wheel -p 0660 \
-i infix-interfaces@2023-08-21.yang -g wheel -p 0660 \
-e vlan-filtering \
-i infix-shell-type@2023-08-21.yang -g wheel -p 0660 \
-i infix-system@2023-08-15.yang -g wheel -p 0660 \
@@ -1,27 +0,0 @@
module infix-if-type {
yang-version 1.1;
namespace "urn:infix:types:ns:yang:1.0";
prefix infixift;
import iana-if-type {
prefix ianaift;
}
organization "KernelKit";
contact "kernelkit@googlegroups.com";
description "Infix extensions to IANA interfaces types";
revision 2023-06-09 {
description "Initial revision.";
reference "internal";
}
/*
* Identities
*/
identity veth {
base ianaift:ilan;
description "Linux virtual Ethernet pair.";
}
}
@@ -0,0 +1,71 @@
module infix-if-type {
yang-version 1.1;
namespace "urn:infix:types:ns:yang:1.0";
prefix infixift;
import iana-if-type {
prefix ianaift;
}
organization "KernelKit";
contact "kernelkit@googlegroups.com";
description "Infix extensions to IANA interfaces types";
revision 2023-08-21 {
description "Add infix-inteface-type to reduce number of supported
interfaces. The derived identities are based on both
this new identity and their parent iana-if-type.";
reference "internal";
}
revision 2023-06-09 {
description "Initial revision.";
reference "internal";
}
/*
* Identities
*/
identity infix-interface-type {
base ianaift:iana-interface-type;
description "Subset of supported iana-if-types.";
}
identity bridge {
base infix-interface-type;
base ianaift:bridge;
description "IEEE bridge interface.";
}
identity ethernet {
base infix-interface-type;
base ianaift:ethernetCsmacd;
description "Any Ethernet-like interfaces, regardless of speed, RFC 3635.";
reference "RFC 3635";
}
identity lag {
base infix-interface-type;
base ianaift:ieee8023adLag;
description "IEEE link aggregate interface.";
}
identity loopback {
base infix-interface-type;
base ianaift:softwareLoopback;
description "Linux loopback interface.";
}
identity other {
base infix-interface-type;
base ianaift:other;
description "Other interface, i.e., unknown.";
}
identity veth {
base infix-interface-type;
base ianaift:ilan;
description "Linux virtual Ethernet pair.";
}
identity vlan {
base infix-interface-type;
base ianaift:l2vlan;
description "Layer 2 Virtual LAN using 802.1Q.";
}
}
@@ -6,6 +6,9 @@ module infix-interfaces {
include infix-if-bridge;
include infix-if-veth;
import infix-if-type {
prefix infixift;
}
import ietf-interfaces {
prefix if;
}
@@ -14,6 +17,12 @@ module infix-interfaces {
contact "kernelkit@googlegroups.com";
description "Linux bridge and lag extensions for ietf-interfaces.";
revision 2023-08-21 {
description "Add deviation to if:type to limit the iana-if-types to
only those supported, also reduce list for CLI <TAB>.";
reference "internal";
}
revision 2023-06-05 {
description "Initial revision.";
reference "internal";
@@ -31,6 +40,14 @@ module infix-interfaces {
}
}
deviation "/if:interfaces/if:interface/if:type" {
deviate replace {
type identityref {
base infixift:infix-interface-type;
}
}
}
deviation "/if:interfaces-state" {
deviate not-supported;
}
+9 -9
View File
@@ -267,24 +267,24 @@ static const char *get_yang_link_type(char *xpath, json_t *iface)
j_val = json_object_get(iface, "linkinfo");
if (!j_val)
return "iana-if-type:ethernetCsmacd";
return "infix-if-type:ethernet";
j_val = json_object_get(j_val, "info_kind");
if (!j_val)
return "iana-if-type:ethernetCsmacd";
return "infix-if-type:ethernet";
if (!json_is_string(j_val)) {
ERROR("Expected a JSON string for 'info_kind'");
return "iana-if-type:other";
return "infix-if-type:other";
}
kind = json_string_value(j_val);
if (strcmp(kind, "veth") == 0)
return "infix-if-type:veth";
if (strcmp(kind, "vlan") == 0)
return "iana-if-type:l2vlan";
return "infix-if-type:vlan";
if (strcmp(kind, "bridge") == 0)
return "iana-if-type:bridge";
return "infix-if-type:bridge";
/**
* We could return ethernetCsmacd here, but it might hide some
@@ -292,15 +292,15 @@ static const char *get_yang_link_type(char *xpath, json_t *iface)
*/
ERROR("Unable to determine info_kind for \"%s\"", xpath);
return "iana-if-type:other";
return "infix-if-type:other";
}
if (strcmp(type, "loopback") == 0)
return "iana-if-type:softwareLoopback";
return "infix-if-type:loopback";
ERROR("Unable to determine iana-if-type for \"%s\"", xpath);
ERROR("Unable to determine infix-if-type for \"%s\"", xpath);
return "iana-if-type:other";
return "infix-if-type:other";
}
static int ly_add_ip_link_data(const struct ly_ctx *ctx, struct lyd_node **parent,