1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

Merge pull request #10618 from yuwata/fix-10615

network: fix several issues in config parser
This commit is contained in:
Lennart Poettering 2018-11-05 17:37:25 +03:00 committed by GitHub
commit a54e373163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 63 additions and 44 deletions

View File

@ -1486,7 +1486,6 @@ Protocol=4
<example> <example>
<title>/etc/systemd/network/25-fou-ipip.netdev</title> <title>/etc/systemd/network/25-fou-ipip.netdev</title>
<programlisting>[NetDev] <programlisting>[NetDev]
[NetDev]
Name=ipip-tun Name=ipip-tun
Kind=ipip Kind=ipip

View File

@ -255,11 +255,10 @@ int config_parse_ifalias(const char *unit,
return 0; return 0;
} }
free(*s); if (isempty(n))
if (*n) *s = mfree(*s);
*s = TAKE_PTR(n);
else else
*s = NULL; free_and_replace(*s, n);
return 0; return 0;
} }
@ -294,7 +293,7 @@ int config_parse_hwaddr(const char *unit,
return 0; return 0;
} }
*hwaddr = TAKE_PTR(n); free_and_replace(*hwaddr, n);
return 0; return 0;
} }

View File

@ -376,10 +376,8 @@ int config_parse_arp_ip_target_address(const char *unit,
return 0; return 0;
} }
LIST_PREPEND(arp_ip_target, b->arp_ip_targets, buffer); LIST_PREPEND(arp_ip_target, b->arp_ip_targets, TAKE_PTR(buffer));
b->n_arp_ip_targets++; b->n_arp_ip_targets++;
buffer = NULL;
} }
if (b->n_arp_ip_targets > NETDEV_BOND_ARP_TARGETS_MAX) if (b->n_arp_ip_targets > NETDEV_BOND_ARP_TARGETS_MAX)

View File

@ -108,7 +108,9 @@ GENEVE.TOS, config_parse_uint8, 0,
GENEVE.TTL, config_parse_uint8, 0, offsetof(Geneve, ttl) GENEVE.TTL, config_parse_uint8, 0, offsetof(Geneve, ttl)
GENEVE.UDPChecksum, config_parse_bool, 0, offsetof(Geneve, udpcsum) GENEVE.UDPChecksum, config_parse_bool, 0, offsetof(Geneve, udpcsum)
GENEVE.UDP6ZeroCheckSumRx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumrx) GENEVE.UDP6ZeroCheckSumRx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumrx)
GENEVE.UDP6ZeroChecksumRx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumrx)
GENEVE.UDP6ZeroCheckSumTx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumtx) GENEVE.UDP6ZeroCheckSumTx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumtx)
GENEVE.UDP6ZeroChecksumTx, config_parse_bool, 0, offsetof(Geneve, udp6zerocsumtx)
GENEVE.DestinationPort, config_parse_ip_port, 0, offsetof(Geneve, dest_port) GENEVE.DestinationPort, config_parse_ip_port, 0, offsetof(Geneve, dest_port)
GENEVE.FlowLabel, config_parse_geneve_flow_label, 0, 0 GENEVE.FlowLabel, config_parse_geneve_flow_label, 0, 0
Tun.OneQueue, config_parse_bool, 0, offsetof(TunTap, one_queue) Tun.OneQueue, config_parse_bool, 0, offsetof(TunTap, one_queue)

View File

@ -4,5 +4,6 @@
const NetDevVTable vcan_vtable = { const NetDevVTable vcan_vtable = {
.object_size = sizeof(VCan), .object_size = sizeof(VCan),
.sections = "Match\0NetDev\0",
.create_type = NETDEV_CREATE_INDEPENDENT, .create_type = NETDEV_CREATE_INDEPENDENT,
}; };

View File

@ -27,7 +27,7 @@ static int netdev_vrf_fill_message_create(NetDev *netdev, Link *link, sd_netlink
const NetDevVTable vrf_vtable = { const NetDevVTable vrf_vtable = {
.object_size = sizeof(Vrf), .object_size = sizeof(Vrf),
.sections = "NetDev\0VRF\0", .sections = "Match\0NetDev\0VRF\0",
.fill_message_create = netdev_vrf_fill_message_create, .fill_message_create = netdev_vrf_fill_message_create,
.create_type = NETDEV_CREATE_MASTER, .create_type = NETDEV_CREATE_MASTER,
}; };

View File

@ -91,10 +91,8 @@ void address_free(Address *address) {
assert(address->network->n_static_addresses > 0); assert(address->network->n_static_addresses > 0);
address->network->n_static_addresses--; address->network->n_static_addresses--;
if (address->section) { if (address->section)
hashmap_remove(address->network->addresses_by_section, address->section); hashmap_remove(address->network->addresses_by_section, address->section);
network_config_section_free(address->section);
}
} }
if (address->link) { if (address->link) {
@ -105,6 +103,8 @@ void address_free(Address *address) {
memzero(&address->link->ipv6ll_address, sizeof(struct in6_addr)); memzero(&address->link->ipv6ll_address, sizeof(struct in6_addr));
} }
network_config_section_free(address->section);
free(address->label);
free(address); free(address);
} }

View File

@ -200,7 +200,7 @@ int config_parse_fdb_hwaddr(
&fdb_entry->mac_addr->ether_addr_octet[4], &fdb_entry->mac_addr->ether_addr_octet[4],
&fdb_entry->mac_addr->ether_addr_octet[5]); &fdb_entry->mac_addr->ether_addr_octet[5]);
if (ETHER_ADDR_LEN != r) { if (r != ETHER_ADDR_LEN) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring assignment: %s", rvalue); log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring assignment: %s", rvalue);
return 0; return 0;
} }

View File

@ -88,16 +88,16 @@ void ipv6_proxy_ndp_address_free(IPv6ProxyNDPAddress *ipv6_proxy_ndp_address) {
} }
int config_parse_ipv6_proxy_ndp_address( int config_parse_ipv6_proxy_ndp_address(
const char *unit, const char *unit,
const char *filename, const char *filename,
unsigned line, unsigned line,
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *lvalue, const char *lvalue,
int ltype, int ltype,
const char *rvalue, const char *rvalue,
void *data, void *data,
void *userdata) { void *userdata) {
Network *network = userdata; Network *network = userdata;
_cleanup_(ipv6_proxy_ndp_address_freep) IPv6ProxyNDPAddress *ipv6_proxy_ndp_address = NULL; _cleanup_(ipv6_proxy_ndp_address_freep) IPv6ProxyNDPAddress *ipv6_proxy_ndp_address = NULL;

View File

@ -201,7 +201,7 @@ static int manager_udev_process_link(sd_device_monitor *monitor, sd_device *devi
} }
if (!STR_IN_SET(action, "add", "change")) { if (!STR_IN_SET(action, "add", "change")) {
log_device_debug(device, "Ignoring udev %s event for device: %m", action); log_device_debug(device, "Ignoring udev %s event for device.", action);
return 0; return 0;
} }

View File

@ -38,8 +38,8 @@ Link.AllMulticast, config_parse_tristate,
Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged) Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged)
Link.RequiredForOnline, config_parse_bool, 0, offsetof(Network, required_for_online) Link.RequiredForOnline, config_parse_bool, 0, offsetof(Network, required_for_online)
Network.Description, config_parse_string, 0, offsetof(Network, description) Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge) Network.Bridge, config_parse_netdev, 0, 0
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond) Network.Bond, config_parse_netdev, 0, 0
Network.VLAN, config_parse_netdev, 0, 0 Network.VLAN, config_parse_netdev, 0, 0
Network.MACVLAN, config_parse_netdev, 0, 0 Network.MACVLAN, config_parse_netdev, 0, 0
Network.MACVTAP, config_parse_netdev, 0, 0 Network.MACVTAP, config_parse_netdev, 0, 0

View File

@ -607,14 +607,17 @@ int config_parse_netdev(const char *unit,
switch (kind) { switch (kind) {
case NETDEV_KIND_BRIDGE: case NETDEV_KIND_BRIDGE:
network->bridge = netdev_unref(network->bridge);
network->bridge = netdev; network->bridge = netdev;
break; break;
case NETDEV_KIND_BOND: case NETDEV_KIND_BOND:
network->bond = netdev_unref(network->bond);
network->bond = netdev; network->bond = netdev;
break; break;
case NETDEV_KIND_VRF: case NETDEV_KIND_VRF:
network->vrf = netdev_unref(network->vrf);
network->vrf = netdev; network->vrf = netdev;
break; break;

View File

@ -78,6 +78,8 @@ typedef enum RADVPrefixDelegation {
RADV_PREFIX_DELEGATION_STATIC, RADV_PREFIX_DELEGATION_STATIC,
RADV_PREFIX_DELEGATION_DHCP6, RADV_PREFIX_DELEGATION_DHCP6,
RADV_PREFIX_DELEGATION_BOTH, RADV_PREFIX_DELEGATION_BOTH,
_RADV_PREFIX_DELEGATION_MAX,
_RADV_PREFIX_DELEGATION_INVALID = -1,
} RADVPrefixDelegation; } RADVPrefixDelegation;
typedef struct NetworkConfigSection { typedef struct NetworkConfigSection {
@ -316,3 +318,6 @@ DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
const char* lldp_mode_to_string(LLDPMode m) _const_; const char* lldp_mode_to_string(LLDPMode m) _const_;
LLDPMode lldp_mode_from_string(const char *s) _pure_; LLDPMode lldp_mode_from_string(const char *s) _pure_;
const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_;
RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;

View File

@ -12,8 +12,21 @@
#include "parse-util.h" #include "parse-util.h"
#include "sd-radv.h" #include "sd-radv.h"
#include "string-util.h" #include "string-util.h"
#include "string-table.h"
#include "strv.h" #include "strv.h"
static const char * const radv_prefix_delegation_table[_RADV_PREFIX_DELEGATION_MAX] = {
[RADV_PREFIX_DELEGATION_NONE] = "no",
[RADV_PREFIX_DELEGATION_STATIC] = "static",
[RADV_PREFIX_DELEGATION_DHCP6] = "dhcpv6",
[RADV_PREFIX_DELEGATION_BOTH] = "yes",
};
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(
radv_prefix_delegation,
RADVPrefixDelegation,
RADV_PREFIX_DELEGATION_BOTH);
int config_parse_router_prefix_delegation( int config_parse_router_prefix_delegation(
const char *unit, const char *unit,
const char *filename, const char *filename,
@ -27,7 +40,7 @@ int config_parse_router_prefix_delegation(
void *userdata) { void *userdata) {
Network *network = userdata; Network *network = userdata;
int d; RADVPrefixDelegation d;
assert(filename); assert(filename);
assert(section); assert(section);
@ -35,21 +48,14 @@ int config_parse_router_prefix_delegation(
assert(rvalue); assert(rvalue);
assert(data); assert(data);
if (streq(rvalue, "static")) d = radv_prefix_delegation_from_string(rvalue);
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_STATIC; if (d < 0) {
else if (streq(rvalue, "dhcpv6")) log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Invalid router prefix delegation '%s', ignoring assignment.", rvalue);
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_DHCP6; return 0;
else {
d = parse_boolean(rvalue);
if (d > 0)
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_BOTH;
else
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_NONE;
if (d < 0)
log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Router prefix delegation '%s' is invalid, ignoring assignment: %m", rvalue);
} }
network->router_prefix_delegation = d;
return 0; return 0;
} }
@ -92,13 +98,12 @@ void prefix_free(Prefix *prefix) {
assert(prefix->network->n_static_prefixes > 0); assert(prefix->network->n_static_prefixes > 0);
prefix->network->n_static_prefixes--; prefix->network->n_static_prefixes--;
if (prefix->section) { if (prefix->section)
hashmap_remove(prefix->network->prefixes_by_section, hashmap_remove(prefix->network->prefixes_by_section,
prefix->section); prefix->section);
network_config_section_free(prefix->section);
}
} }
network_config_section_free(prefix->section);
prefix->radv_prefix = sd_radv_prefix_unref(prefix->radv_prefix); prefix->radv_prefix = sd_radv_prefix_unref(prefix->radv_prefix);
free(prefix); free(prefix);

View File

@ -33,6 +33,7 @@ int main(int argc, char **argv) {
test_table(lldp_mode, LLDP_MODE); test_table(lldp_mode, LLDP_MODE);
test_table(netdev_kind, NETDEV_KIND); test_table(netdev_kind, NETDEV_KIND);
test_table(nl_union_link_info_data, NL_UNION_LINK_INFO_DATA); test_table(nl_union_link_info_data, NL_UNION_LINK_INFO_DATA);
test_table(radv_prefix_delegation, RADV_PREFIX_DELEGATION);
test_table(wol, WOL); test_table(wol, WOL);
test_table_sparse(ipvlan_mode, NETDEV_IPVLAN_MODE); test_table_sparse(ipvlan_mode, NETDEV_IPVLAN_MODE);

View File

@ -9,6 +9,9 @@ int parse_vlanid(const char *p, uint16_t *ret) {
uint16_t id; uint16_t id;
int r; int r;
assert(p);
assert(ret);
r = safe_atou16(p, &id); r = safe_atou16(p, &id);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -4,5 +4,7 @@ Name=veth99
[Network] [Network]
IPv6AcceptRA=false IPv6AcceptRA=false
DHCP=ipv4 DHCP=ipv4
[DHCP]
UseRoutes=true UseRoutes=true
UseTimezone=true UseTimezone=true

View File

@ -61,6 +61,7 @@ class Utilities():
for link in links: for link in links:
if os.path.exists(os.path.join('/sys/class/net', link)): if os.path.exists(os.path.join('/sys/class/net', link)):
subprocess.call(['ip', 'link', 'del', 'dev', link]) subprocess.call(['ip', 'link', 'del', 'dev', link])
time.sleep(1)
def read_ipv6_sysctl_attr(self, link, attribute): def read_ipv6_sysctl_attr(self, link, attribute):
with open(os.path.join(os.path.join(network_sysctl_ipv6_path, link), attribute)) as f: with open(os.path.join(os.path.join(network_sysctl_ipv6_path, link), attribute)) as f: