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>
<title>/etc/systemd/network/25-fou-ipip.netdev</title>
<programlisting>[NetDev]
[NetDev]
Name=ipip-tun
Kind=ipip

View File

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

View File

@ -376,10 +376,8 @@ int config_parse_arp_ip_target_address(const char *unit,
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++;
buffer = NULL;
}
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.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.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.FlowLabel, config_parse_geneve_flow_label, 0, 0
Tun.OneQueue, config_parse_bool, 0, offsetof(TunTap, one_queue)

View File

@ -4,5 +4,6 @@
const NetDevVTable vcan_vtable = {
.object_size = sizeof(VCan),
.sections = "Match\0NetDev\0",
.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 = {
.object_size = sizeof(Vrf),
.sections = "NetDev\0VRF\0",
.sections = "Match\0NetDev\0VRF\0",
.fill_message_create = netdev_vrf_fill_message_create,
.create_type = NETDEV_CREATE_MASTER,
};

View File

@ -91,10 +91,8 @@ void address_free(Address *address) {
assert(address->network->n_static_addresses > 0);
address->network->n_static_addresses--;
if (address->section) {
if (address->section)
hashmap_remove(address->network->addresses_by_section, address->section);
network_config_section_free(address->section);
}
}
if (address->link) {
@ -105,6 +103,8 @@ void address_free(Address *address) {
memzero(&address->link->ipv6ll_address, sizeof(struct in6_addr));
}
network_config_section_free(address->section);
free(address->label);
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[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);
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(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
Network *network = userdata;
_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")) {
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;
}

View File

@ -38,8 +38,8 @@ Link.AllMulticast, config_parse_tristate,
Link.Unmanaged, config_parse_bool, 0, offsetof(Network, unmanaged)
Link.RequiredForOnline, config_parse_bool, 0, offsetof(Network, required_for_online)
Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge)
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
Network.Bridge, config_parse_netdev, 0, 0
Network.Bond, config_parse_netdev, 0, 0
Network.VLAN, config_parse_netdev, 0, 0
Network.MACVLAN, 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) {
case NETDEV_KIND_BRIDGE:
network->bridge = netdev_unref(network->bridge);
network->bridge = netdev;
break;
case NETDEV_KIND_BOND:
network->bond = netdev_unref(network->bond);
network->bond = netdev;
break;
case NETDEV_KIND_VRF:
network->vrf = netdev_unref(network->vrf);
network->vrf = netdev;
break;

View File

@ -78,6 +78,8 @@ typedef enum RADVPrefixDelegation {
RADV_PREFIX_DELEGATION_STATIC,
RADV_PREFIX_DELEGATION_DHCP6,
RADV_PREFIX_DELEGATION_BOTH,
_RADV_PREFIX_DELEGATION_MAX,
_RADV_PREFIX_DELEGATION_INVALID = -1,
} RADVPrefixDelegation;
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_;
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 "sd-radv.h"
#include "string-util.h"
#include "string-table.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(
const char *unit,
const char *filename,
@ -27,7 +40,7 @@ int config_parse_router_prefix_delegation(
void *userdata) {
Network *network = userdata;
int d;
RADVPrefixDelegation d;
assert(filename);
assert(section);
@ -35,21 +48,14 @@ int config_parse_router_prefix_delegation(
assert(rvalue);
assert(data);
if (streq(rvalue, "static"))
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_STATIC;
else if (streq(rvalue, "dhcpv6"))
network->router_prefix_delegation = RADV_PREFIX_DELEGATION_DHCP6;
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);
d = radv_prefix_delegation_from_string(rvalue);
if (d < 0) {
log_syntax(unit, LOG_ERR, filename, line, -EINVAL, "Invalid router prefix delegation '%s', ignoring assignment.", rvalue);
return 0;
}
network->router_prefix_delegation = d;
return 0;
}
@ -92,13 +98,12 @@ void prefix_free(Prefix *prefix) {
assert(prefix->network->n_static_prefixes > 0);
prefix->network->n_static_prefixes--;
if (prefix->section) {
if (prefix->section)
hashmap_remove(prefix->network->prefixes_by_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);
free(prefix);

View File

@ -33,6 +33,7 @@ int main(int argc, char **argv) {
test_table(lldp_mode, LLDP_MODE);
test_table(netdev_kind, NETDEV_KIND);
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_sparse(ipvlan_mode, NETDEV_IPVLAN_MODE);

View File

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

View File

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

View File

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