Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ All notable changes to the project are documented in this file.

- The CLI accepts an unambiguous prefix of a command name, e.g. `sh int`
for `show interface`
- The CLI accepts IP addresses in CIDR notation, e.g. `set ipv4 address
192.168.1.1/24`. An IPv4 address set without a prefix length gets the
classful default: /8, /16, or /24
- Add a `log` RPC to `infix-syslog`, and a matching admin-exec `log`
command in the CLI, for injecting messages in the system log over
NETCONF/RESTCONF, issue #1639. Severity, app-name, msgid, and RFC 5424
Expand Down
16 changes: 16 additions & 0 deletions doc/ip.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,22 @@ lo ethernet UP 00:00:00:00:00:00
admin@example:/>
</code></pre>

The address and prefix length can also be given in CIDR notation, e.g.,
`set address 10.0.1.1/24`. This works for IPv6 addresses as well, and
with the `edit` and `delete` commands.

An IPv4 address set without a prefix length gets the default length of
its address class:

| **Class** | **First octet** | **Prefix length** |
|-----------|-----------------|-------------------|
| A | 0-127 | 8 |
| B | 128-191 | 16 |
| C | 192-223 | 24 |

Multicast and reserved addresses (class D and E) have no default and
need an explicit prefix length.

### Static IPv6 address

![Setting static IPv6](img/ip-address-example-ipv6-static.svg)
Expand Down
2 changes: 1 addition & 1 deletion package/klish-plugin-sysrepo/klish-plugin-sysrepo.hash
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Locally calculated
sha256 9d9d33b873917ca5d0bdcc47a36d2fd385971ab0c045d1472fcadf95ee5bcf5b LICENCE
sha256 0c07cb330a9f3855eefe9f9fa0d9f91d921cbf369571e943ab9ac264cd281db0 klish-plugin-sysrepo-3b4e69780e64f0b8f42dc3784defe72285911ad4-git4.tar.gz
sha256 c5ae2e3770a5e5a7bb81f73ac39a4f84688b5cf1fbcaf4a27b35e64329886d5f klish-plugin-sysrepo-a112518ec2fb32ae56dc10d624119ba17ae46d73-git4.tar.gz
2 changes: 1 addition & 1 deletion package/klish-plugin-sysrepo/klish-plugin-sysrepo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
################################################################################

KLISH_PLUGIN_SYSREPO_VERSION = 3b4e69780e64f0b8f42dc3784defe72285911ad4
KLISH_PLUGIN_SYSREPO_VERSION = a112518ec2fb32ae56dc10d624119ba17ae46d73
KLISH_PLUGIN_SYSREPO_SITE = https://github.com/kernelkit/klish-plugin-sysrepo.git
KLISH_PLUGIN_SYSREPO_SITE_METHOD = git
KLISH_PLUGIN_SYSREPO_LICENSE = BSD-3
Expand Down
4 changes: 4 additions & 0 deletions src/confd/src/interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ static int ifchange_cand(sr_session_ctx_t *session, uint32_t sub_id, const char
if (err)
break;

err = ifchange_cand_infer_ipv4_prefix(session, new);
if (err)
break;

err = cni_ifchange_cand_infer_type(session, new->xpath);
if (err)
break;
Expand Down
1 change: 1 addition & 0 deletions src/confd/src/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ int interfaces_get_all_l3(const struct lyd_node *tree, char ***ifaces);
int interfaces_validate_keys(sr_session_ctx_t *session, struct lyd_node *config);

/* ip.c */
int ifchange_cand_infer_ipv4_prefix(sr_session_ctx_t *session, const sr_val_t *val);
int netdag_gen_ipv6_autoconf(struct dagger *net, struct lyd_node *cif,
struct lyd_node *dif, FILE *ip);
int netdag_gen_ipv4_autoconf(struct dagger *net, struct lyd_node *cif,
Expand Down
38 changes: 38 additions & 0 deletions src/confd/src/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,44 @@

#include "interfaces.h"

/* Classful default for IPv4 addresses set without a prefix length */
int ifchange_cand_infer_ipv4_prefix(sr_session_ctx_t *session, const sr_val_t *val)
{
sr_val_t inferred = { .type = SR_UINT8_T };
sr_error_t err = SR_ERR_OK;
struct in_addr ina;
uint32_t addr;
char *xpath;
size_t cnt;

if (!strstr(val->xpath, ":ipv4/address[") || fnmatch("*]/ip", val->xpath, 0))
return SR_ERR_OK;
if (inet_pton(AF_INET, val->data.string_val, &ina) != 1)
return SR_ERR_OK;

addr = ntohl(ina.s_addr);
if (IN_CLASSA(addr))
inferred.data.uint8_val = 8;
else if (IN_CLASSB(addr))
inferred.data.uint8_val = 16;
else if (IN_CLASSC(addr))
inferred.data.uint8_val = 24;
else
return SR_ERR_OK; /* class D/E, no default */

xpath = strdup(val->xpath);
if (!xpath)
return SR_ERR_SYS;
*strrchr(xpath, '/') = 0;

err = srx_nitems(session, &cnt, "%s/prefix-length", xpath);
if (!err && !cnt)
err = srx_set_item(session, &inferred, 0, "%s/prefix-length", xpath);

free(xpath);
return err;
}

int netdag_gen_ipv6_autoconf(struct dagger *net, struct lyd_node *cif,
struct lyd_node *dif, FILE *ip)
{
Expand Down
Loading