Skip to content

Commit

Permalink
Merge pull request #513 from ssahani/ctl
Browse files Browse the repository at this point in the history
Allow to configure ipv6 link local address gen mode
  • Loading branch information
ssahani authored Jun 8, 2023
2 parents 6c72508 + da13552 commit ba83e28
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/network-config-manager.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ int ncm_link_acquire_mtu(const char *ifname, uint32_t *ret);

int ncm_link_set_network_ipv6_dad(int argc, char *argv[]);
int ncm_link_set_network_ipv6_mtu(int argc, char *argv[]);
int ncm_link_set_network_ipv6_link_local_address_generation_mode(int argc, char *argv[]);

int ncm_link_set_network_section(int argc, char *argv[]);
int ncm_link_status(int argc, char *argv[]);
Expand Down
31 changes: 31 additions & 0 deletions src/manager/network-config-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,37 @@ _public_ int ncm_link_set_network_ipv6_dad(int argc, char *argv[]) {
return manager_set_link_ipv6_dad(p, r);
}

_public_ int ncm_link_set_network_ipv6_link_local_address_generation_mode(int argc, char *argv[]) {
_cleanup_(config_manager_freep) ConfigManager *m = NULL;
_auto_cleanup_ IfNameIndex *p = NULL;
int r;

for (int i = 1; i < argc; i++) {
if (str_eq_fold(argv[i], "dev")) {
parse_next_arg(argv, argc, i);

r = parse_ifname_or_index(argv[i], &p);
if (r < 0) {
log_warning("Failed to find device: %s", argv[i]);
return r;
}
}
}

if (!p) {
log_warning("Failed to find device: %s", strerror(EINVAL));
return -EINVAL;
}

r = ipv6_link_local_address_gen_type_to_mode(argv[3]);
if (r < 0) {
log_warning("Failed to parse '%s': %s", argv[3], strerror(-r));
return r;
}

return manager_set_link_ipv6_link_local_address_generation_mode(p, r);
}

_public_ int ncm_link_set_dhcp4_section(int argc, char *argv[]) {
_cleanup_(config_manager_freep) ConfigManager *m = NULL;
_auto_cleanup_ IfNameIndex *p = NULL;
Expand Down
4 changes: 4 additions & 0 deletions src/manager/network-manager-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ static int help(void) {
" set-ipv4proxyarp dev [DEVICE] [IPv4ProxyARP BOOLEAN] Configures Link proxy ARP for IPv4.\n"
" set-ipv6proxyndp dev [DEVICE] [IPv6ProxyNDP BOOLEAN] Configures Link proxy NDP for IPv6.\n"
" set-conf-wc dev [DEVICE] [ConfigureWithoutCarrier BOOLEAN] Allows networkd to configure link even if it has no carrier.\n"
" set-ipv6dad dev [DEVICE] [IPv6DuplicateAddressDetection BOOLEAN] Allows Configures the amount of IPv6 Duplicate Address Detection (DAD) probes to send.\n"
" set-ipv6-ll-addr-gen-mode dev [DEVICE] [IPv6LinkLocalAddressGenerationMode eui64|stable-privacy|none|random] Specifies how IPv6 link-local address is generated.\n"
" set-conf-wc dev [DEVICE] [ConfigureWithoutCarrier BOOLEAN] Allows networkd to configure link even if it has no carrier.\n"
" set-dhcp4 dev [DEVICE] [use-dns BOOLEAN] [use-domains BOOLEAN] [use-mtu BOOLEAN] [use-ntp BOOLEAN] [send-release BOOLEAN]."
"\n\t\t\t\t [use-hostname BOOLEAN] [use-routes BOOLEAN] [use-gw BOOLEAN] [use-tz BOOLEAN] Configures Link DHCPv4\n"
" set-dhcp6 dev [DEVICE] [use-dns BOOLEAN] [use-domains BOOLEAN] [rapid-commit BOOLEAN] [use-addr BOOLEAN] [use-delegataed-prefix BOOLEAN]"
Expand Down Expand Up @@ -395,6 +398,7 @@ static int cli_run(int argc, char *argv[]) {
{ "set-ipv6proxyndp", "pxyndp6", 3, WORD_ANY, false, ncm_link_set_network_section },
{ "set-conf-wc", "cwc", 3, WORD_ANY, false, ncm_link_set_network_section },
{ "set-ipv6dad", "ipv6dad", 3, WORD_ANY, false, ncm_link_set_network_ipv6_dad },
{ "set-ipv6-ll-addr-gen-mode", "ipv6llagm", 3, WORD_ANY, false, ncm_link_set_network_ipv6_link_local_address_generation_mode},
{ "set-dhcp4", "dhcp4", 4, WORD_ANY, false, ncm_link_set_dhcp4_section },
{ "set-dhcp6", "dhcp6", 4, WORD_ANY, false, ncm_link_set_dhcp6_section },
{ "add-dhcpv4-server", "adhcp4-srv" , 2, WORD_ANY, false, ncm_link_add_dhcpv4_server },
Expand Down
20 changes: 20 additions & 0 deletions src/manager/network-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ int manager_set_link_ipv6_dad(const IfNameIndex *ifidx, int dad) {
return dbus_network_reload();
}

int manager_set_link_ipv6_link_local_address_generation_mode(const IfNameIndex *ifidx, int mode) {
_auto_cleanup_ char *network = NULL;
int r;

assert(ifidx);

r = create_or_parse_network_file(ifidx, &network);
if (r < 0)
return r;

r = set_config_file_str(network, "Network", "IPv6LinkLocalAddressGenerationMode", ipv6_link_local_address_gen_type_to_name(mode));
if (r < 0) {
log_warning("Failed to update IPv6LinkLocalAddressGenerationMode= to configuration file '%s': %s", network, strerror(-r));
return r;
}

return dbus_network_reload();
}


int manager_get_link_dns(const IfNameIndex *ifidx, char **ret) {
_auto_cleanup_ char *network = NULL, *config = NULL;
int r;
Expand Down
1 change: 1 addition & 0 deletions src/manager/network-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int manager_set_link_dhcp4_client_identifier(const IfNameIndex *ifidx, const DHC
int manager_get_link_dhcp4_client_identifier(const IfNameIndex *ifidx, DHCPClientIdentifier *ret);

int manager_set_link_ipv6_dad(const IfNameIndex *ifidx, int dad);
int manager_set_link_ipv6_link_local_address_generation_mode(const IfNameIndex *ifidx, int mode);

int manager_get_link_dns(const IfNameIndex *ifidx, char **ret);
bool manager_is_link_static_address(const IfNameIndex *ifidx);
Expand Down
14 changes: 13 additions & 1 deletion tests/network-config-manager-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def test_cli_set_act_policy(self):
assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Link', 'ActivationPolicy') == 'always-up')

def test_cli_set_dhcp_client_type(self):
def test_cli_set_ipv6_dad_type(self):
assert(link_exist('test99') == True)

subprocess.check_call("nmctl set-ipv6dad dev test99 no", shell = True)
Expand All @@ -978,6 +978,18 @@ def test_cli_set_dhcp_client_type(self):
assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Network', 'IPv6DuplicateAddressDetection') == '0')

def test_cli_set_ipv6_ll_address_generation_mode(self):
assert(link_exist('test99') == True)

subprocess.check_call("nmctl set-ipv6-ll-addr-gen-mode dev test99 stable-privacy", shell = True)

assert(unit_exist('10-test99.network') == True)
parser = configparser.ConfigParser()
parser.read(os.path.join(networkd_unit_file_path, '10-test99.network'))

assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Network', 'IPv6LinkLocalAddressGenerationMode') == 'stable-privacy')

def test_cli_set_dhcp_client_type(self):
assert(link_exist('test99') == True)

Expand Down

0 comments on commit ba83e28

Please sign in to comment.