From 8b9504ffa59b5931c5e6e02192bf66be6349c9d8 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 24 Apr 2023 20:34:44 +0200 Subject: [PATCH] src/confd: augment ietf-ip with an 'autoconf' setting also for IPv4 This patch adds a first Infix model to augment ietf-ip with a node, similar to the IPv6 'autoconf' node, also for IPv4. For IPv6 the autoconf feature comes built-in, for IPv4 it is defined in RFC3927. The setting behaves the same as for IPv6, but in the case of IPv4 we enable avahi-autoipd per interface to acquire the 169.254/16 address. Signed-off-by: Joachim Wiberg --- src/confd/src/ietf-interfaces.c | 20 ++++++++++- src/confd/yang/infix-ip@2023-04-24.yang | 47 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/confd/yang/infix-ip@2023-04-24.yang diff --git a/src/confd/src/ietf-interfaces.c b/src/confd/src/ietf-interfaces.c index 1837de4a..1cb72899 100644 --- a/src/confd/src/ietf-interfaces.c +++ b/src/confd/src/ietf-interfaces.c @@ -35,6 +35,7 @@ static const struct srx_module_requirement ietf_if_reqs[] = { { .dir = YANG_PATH_, .name = "ietf-interfaces", .rev = "2018-02-20", .features = iffeat }, { .dir = YANG_PATH_, .name = "iana-if-type", .rev = "2023-01-26" }, { .dir = YANG_PATH_, .name = "ietf-ip", .rev = "2018-02-22", .features = ipfeat }, + { .dir = YANG_PATH_, .name = "infix-ip", .rev = "2023-04-24" }, { NULL } }; @@ -232,6 +233,16 @@ static int ifchange_cand(sr_session_ctx_t *session, uint32_t sub_id, const char return SR_ERR_OK; } +static void zeroconf_init(char *ifname) +{ + systemf("initctl enable zeroconf@%s.conf", ifname); +} + +static void zeroconf_exit(char *ifname) +{ + systemf("initctl disable zeroconf@%s.conf", ifname); +} + static int ifchange(sr_session_ctx_t *session, uint32_t sub_id, const char *module, const char *xpath, sr_event_t event, unsigned request_id, void *priv) { @@ -265,8 +276,15 @@ static int ifchange(sr_session_ctx_t *session, uint32_t sub_id, const char *modu "/proc/sys/net/ipv4/conf/%s/forwarding", ifname); systemf("ip addr flush dev %s", ifname); - if (!srx_enabled(session, "%s/ietf-ip:ipv4/enabled", xpath)) + if (!srx_enabled(session, "%s/ietf-ip:ipv4/enabled", xpath)) { + zeroconf_exit(ifname); goto ipv6; + } + + if (!srx_enabled(session, "%s/ietf-ip:ipv4/autoconf/enabled", xpath)) + zeroconf_exit(ifname); + else + zeroconf_init(ifname); snprintf(path, sizeof(path), "%s/ietf-ip:ipv4/address", xpath); rc = sr_get_items(session, path, 0, 0, &addr, &addrcnt); diff --git a/src/confd/yang/infix-ip@2023-04-24.yang b/src/confd/yang/infix-ip@2023-04-24.yang new file mode 100644 index 00000000..663d8904 --- /dev/null +++ b/src/confd/yang/infix-ip@2023-04-24.yang @@ -0,0 +1,47 @@ +module infix-ip { + yang-version 1.1; + namespace "urn:infix:params:xml:ns:yang:infix-ip"; + prefix infix-ip; + + import ietf-interfaces { + prefix if; + } + import ietf-ip { + prefix ip; + } + import ietf-inet-types { + prefix inet; + } + import ietf-yang-types { + prefix yang; + } + + description + "This module augments ietf-ip with an IPv4 link-local autoconf"; + + revision 2023-04-24 { + description + "Initial revision."; + reference + "RFC 7277: A YANG Data Model for IP Management"; + } + + /* + * Data nodes + */ + augment "/if:interfaces/if:interface/ip:ipv4" { + container autoconf { + description + "Parameters to control the autoconfiguration of IPv4 address."; + + leaf enabled { + type boolean; + default false; + description + "Use a ZeroConf/IPv4LL agent to retrieve an 169.254/16 address."; + reference + "RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses"; + } + } + } +}