From f9761a89a84fb4aa4502238334c1a40e6d052000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 22 Nov 2019 10:53:26 +0100 Subject: shared/conf-parser: turn CONFIG_PARSE_REFUSE_BOM flag into a local variable This is an internal implementation detail. --- src/shared/conf-parser.c | 6 +++--- src/shared/conf-parser.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 3269d83031..648ac1aa94 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -282,7 +282,7 @@ int config_parse(const char *unit, _cleanup_free_ char *section = NULL, *continuation = NULL; _cleanup_fclose_ FILE *ours = NULL; unsigned line = 0, section_line = 0; - bool section_ignored = false; + bool section_ignored = false, bom_seen = false; int r; assert(filename); @@ -328,13 +328,13 @@ int config_parse(const char *unit, continue; l = buf; - if (!(flags & CONFIG_PARSE_REFUSE_BOM)) { + if (!bom_seen) { char *q; q = startswith(buf, UTF8_BYTE_ORDER_MARK); if (q) { l = q; - flags |= CONFIG_PARSE_REFUSE_BOM; + bom_seen = true; } } diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 04c68b18d8..8a6f877bba 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -17,7 +17,6 @@ typedef enum ConfigParseFlags { CONFIG_PARSE_RELAXED = 1 << 0, CONFIG_PARSE_ALLOW_INCLUDE = 1 << 1, CONFIG_PARSE_WARN = 1 << 2, - CONFIG_PARSE_REFUSE_BOM = 1 << 3, } ConfigParseFlags; /* Argument list for parsers of specific configuration settings. */ -- cgit v1.2.1 From 94a404cb0357fd30bee34ee94cbb481e97098ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 22 Nov 2019 10:53:48 +0100 Subject: shared/conf-parser: document what the flags do --- src/shared/conf-parser.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 8a6f877bba..9ec7777867 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -14,9 +14,9 @@ /* An abstract parser for simple, line based, shallow configuration files consisting of variable assignments only. */ typedef enum ConfigParseFlags { - CONFIG_PARSE_RELAXED = 1 << 0, - CONFIG_PARSE_ALLOW_INCLUDE = 1 << 1, - CONFIG_PARSE_WARN = 1 << 2, + CONFIG_PARSE_RELAXED = 1 << 0, /* Do not warn about unknown non-extension fields */ + CONFIG_PARSE_ALLOW_INCLUDE = 1 << 1, /* Allow the deprecated .include stanza */ + CONFIG_PARSE_WARN = 1 << 2, /* Emit non-debug messages */ } ConfigParseFlags; /* Argument list for parsers of specific configuration settings. */ -- cgit v1.2.1 From ddeb3f5d4b7ce67c23fde0ad149fb06b29a92f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 22 Nov 2019 11:16:17 +0100 Subject: shared/conf-parser: allow sections to be silently ignored with new -Section syntax If we ignore any uknown section, we will not be able to show any warning if a typo in a section name is made. Let's reverse our approach, and explicitly list sections to ignore instead. I opted to make use the same section list for this, instead of adding a second list, because this list is passed through to many functions and adding yet another parameter to the long signature would be very noisy. --- src/shared/conf-parser.c | 13 ++++++++++++- src/test/test-conf-parser.c | 20 ++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 648ac1aa94..90b31148f3 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -221,8 +221,19 @@ static int parse_line( return -ENOMEM; if (sections && !nulstr_contains(sections, n)) { + bool ignore = flags & CONFIG_PARSE_RELAXED; + const char *t; - if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(n, "X-")) + ignore = ignore || startswith(n, "X-"); + + if (!ignore) + NULSTR_FOREACH(t, sections) + if (streq_ptr(n, startswith(t, "-"))) { + ignore = true; + break; + } + + if (!ignore) log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown section '%s'. Ignoring.", n); free(n); diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index 597265efa6..b392a2b5ec 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -299,6 +299,15 @@ static const char* const config_file[] = { "[Section]\n" "setting1=" /* many continuation lines, together above the limit */ x1000(x1000("x") x10("abcde") "\\\n") "xxx", + + "[Section]\n" + "setting1=2\n" + "[NoWarnSection]\n" + "setting1=3\n" + "[WarnSection]\n" + "setting1=3\n" + "[X-Section]\n" + "setting1=3\n", }; static void test_config_parse(unsigned i, const char *s) { @@ -325,14 +334,12 @@ static void test_config_parse(unsigned i, const char *s) { const char *sections, ConfigItemLookup lookup, const void *table, - bool relaxed, - bool allow_include, - bool warn, + ConfigParseFlags flags, void *userdata) */ r = config_parse(NULL, name, f, - "Section\0", + "Section\0-NoWarnSection\0", config_item_table_lookup, items, CONFIG_PARSE_WARN, NULL); @@ -366,6 +373,11 @@ static void test_config_parse(unsigned i, const char *s) { assert_se(r == -ENOBUFS); assert_se(setting1 == NULL); break; + + case 17: + assert_se(r == 0); + assert_se(streq(setting1, "2")); + break; } } -- cgit v1.2.1 From 130b812f9d682e8dc8b3b85fd58077b3caf0da8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 22 Nov 2019 11:43:26 +0100 Subject: network: warn about unknown sections when parsing .netdev files Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1774242. Now we'll emit the warning about unknown section [Netdev], making the issue much easier to diagnose. --- src/network/netdev/bond.c | 2 +- src/network/netdev/bridge.c | 2 +- src/network/netdev/dummy.c | 2 +- src/network/netdev/fou-tunnel.c | 2 +- src/network/netdev/geneve.c | 2 +- src/network/netdev/ipvlan.c | 4 ++-- src/network/netdev/l2tp-tunnel.c | 2 +- src/network/netdev/macsec.c | 2 +- src/network/netdev/macvlan.c | 4 ++-- src/network/netdev/netdev.c | 4 ++-- src/network/netdev/netdev.h | 29 +++++++++++++++++++++++++++++ src/network/netdev/netdevsim.c | 2 +- src/network/netdev/nlmon.c | 2 +- src/network/netdev/tunnel.c | 20 ++++++++++---------- src/network/netdev/tuntap.c | 4 ++-- src/network/netdev/vcan.c | 2 +- src/network/netdev/veth.c | 2 +- src/network/netdev/vlan.c | 2 +- src/network/netdev/vrf.c | 2 +- src/network/netdev/vxcan.c | 2 +- src/network/netdev/vxlan.c | 2 +- src/network/netdev/wireguard.c | 2 +- src/network/netdev/xfrm.c | 2 +- 23 files changed, 64 insertions(+), 35 deletions(-) diff --git a/src/network/netdev/bond.c b/src/network/netdev/bond.c index 185b155440..8df39e3584 100644 --- a/src/network/netdev/bond.c +++ b/src/network/netdev/bond.c @@ -587,7 +587,7 @@ const NetDevVTable bond_vtable = { .object_size = sizeof(Bond), .init = bond_init, .done = bond_done, - .sections = "Match\0NetDev\0Bond\0", + .sections = NETDEV_COMMON_SECTIONS "Bond\0", .fill_message_create = netdev_bond_fill_message_create, .create_type = NETDEV_CREATE_MASTER, .generate_mac = true, diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index 59a40faef8..6b8f994461 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -355,7 +355,7 @@ static void bridge_init(NetDev *n) { const NetDevVTable bridge_vtable = { .object_size = sizeof(Bridge), .init = bridge_init, - .sections = "Match\0NetDev\0Bridge\0", + .sections = NETDEV_COMMON_SECTIONS "Bridge\0", .post_create = netdev_bridge_post_create, .create_type = NETDEV_CREATE_MASTER, }; diff --git a/src/network/netdev/dummy.c b/src/network/netdev/dummy.c index 23c733cbe7..e06dc02f3a 100644 --- a/src/network/netdev/dummy.c +++ b/src/network/netdev/dummy.c @@ -4,7 +4,7 @@ const NetDevVTable dummy_vtable = { .object_size = sizeof(Dummy), - .sections = "Match\0NetDev\0", + .sections = NETDEV_COMMON_SECTIONS, .create_type = NETDEV_CREATE_INDEPENDENT, .generate_mac = true, }; diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index 7627ccee9c..3cc273c7fe 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -262,7 +262,7 @@ static void fou_tunnel_init(NetDev *netdev) { const NetDevVTable foutnl_vtable = { .object_size = sizeof(FouTunnel), .init = fou_tunnel_init, - .sections = "Match\0NetDev\0FooOverUDP\0", + .sections = NETDEV_COMMON_SECTIONS "FooOverUDP\0", .create = netdev_fou_tunnel_create, .create_type = NETDEV_CREATE_INDEPENDENT, .config_verify = netdev_fou_tunnel_verify, diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c index 771e0292de..b960840a54 100644 --- a/src/network/netdev/geneve.c +++ b/src/network/netdev/geneve.c @@ -348,7 +348,7 @@ static void geneve_init(NetDev *netdev) { const NetDevVTable geneve_vtable = { .object_size = sizeof(Geneve), .init = geneve_init, - .sections = "Match\0NetDev\0GENEVE\0", + .sections = NETDEV_COMMON_SECTIONS "GENEVE\0", .create = netdev_geneve_create, .create_type = NETDEV_CREATE_INDEPENDENT, .config_verify = netdev_geneve_verify, diff --git a/src/network/netdev/ipvlan.c b/src/network/netdev/ipvlan.c index 53b4bc944f..1d87cfa865 100644 --- a/src/network/netdev/ipvlan.c +++ b/src/network/netdev/ipvlan.c @@ -74,7 +74,7 @@ static void ipvlan_init(NetDev *n) { const NetDevVTable ipvlan_vtable = { .object_size = sizeof(IPVlan), .init = ipvlan_init, - .sections = "Match\0NetDev\0IPVLAN\0", + .sections = NETDEV_COMMON_SECTIONS "IPVLAN\0", .fill_message_create = netdev_ipvlan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .generate_mac = true, @@ -83,7 +83,7 @@ const NetDevVTable ipvlan_vtable = { const NetDevVTable ipvtap_vtable = { .object_size = sizeof(IPVlan), .init = ipvlan_init, - .sections = "Match\0NetDev\0IPVTAP\0", + .sections = NETDEV_COMMON_SECTIONS "IPVTAP\0", .fill_message_create = netdev_ipvlan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .generate_mac = true, diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c index f10506af1e..19683c0a00 100644 --- a/src/network/netdev/l2tp-tunnel.c +++ b/src/network/netdev/l2tp-tunnel.c @@ -723,7 +723,7 @@ static void l2tp_tunnel_done(NetDev *netdev) { const NetDevVTable l2tptnl_vtable = { .object_size = sizeof(L2tpTunnel), .init = l2tp_tunnel_init, - .sections = "Match\0NetDev\0L2TP\0L2TPSession\0", + .sections = NETDEV_COMMON_SECTIONS "L2TP\0L2TPSession\0", .create_after_configured = l2tp_create_tunnel, .done = l2tp_tunnel_done, .create_type = NETDEV_CREATE_AFTER_CONFIGURED, diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index 25dc23ff03..010e16bcaf 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -1235,7 +1235,7 @@ static void macsec_done(NetDev *netdev) { const NetDevVTable macsec_vtable = { .object_size = sizeof(MACsec), .init = macsec_init, - .sections = "Match\0NetDev\0MACsec\0MACsecReceiveChannel\0MACsecTransmitAssociation\0MACsecReceiveAssociation\0", + .sections = NETDEV_COMMON_SECTIONS "MACsec\0MACsecReceiveChannel\0MACsecTransmitAssociation\0MACsecReceiveAssociation\0", .fill_message_create = netdev_macsec_fill_message_create, .post_create = netdev_macsec_configure, .done = macsec_done, diff --git a/src/network/netdev/macvlan.c b/src/network/netdev/macvlan.c index fe596c295a..dbe25e9e34 100644 --- a/src/network/netdev/macvlan.c +++ b/src/network/netdev/macvlan.c @@ -58,7 +58,7 @@ static void macvlan_init(NetDev *n) { const NetDevVTable macvtap_vtable = { .object_size = sizeof(MacVlan), .init = macvlan_init, - .sections = "Match\0NetDev\0MACVTAP\0", + .sections = NETDEV_COMMON_SECTIONS "MACVTAP\0", .fill_message_create = netdev_macvlan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .generate_mac = true, @@ -67,7 +67,7 @@ const NetDevVTable macvtap_vtable = { const NetDevVTable macvlan_vtable = { .object_size = sizeof(MacVlan), .init = macvlan_init, - .sections = "Match\0NetDev\0MACVLAN\0", + .sections = NETDEV_COMMON_SECTIONS "MACVLAN\0", .fill_message_create = netdev_macvlan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .generate_mac = true, diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 6908c4e811..423750a6a0 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -682,9 +682,9 @@ int netdev_load_one(Manager *manager, const char *filename) { dropin_dirname = strjoina(basename(filename), ".d"); r = config_parse_many(filename, NETWORK_DIRS, dropin_dirname, - "Match\0NetDev\0", + NETDEV_COMMON_SECTIONS NETDEV_OTHER_SECTIONS, config_item_perf_lookup, network_netdev_gperf_lookup, - CONFIG_PARSE_WARN|CONFIG_PARSE_RELAXED, netdev_raw); + CONFIG_PARSE_WARN, netdev_raw); if (r < 0) return r; diff --git a/src/network/netdev/netdev.h b/src/network/netdev/netdev.h index 8d16ec5769..078d0aca4f 100644 --- a/src/network/netdev/netdev.h +++ b/src/network/netdev/netdev.h @@ -8,6 +8,35 @@ #include "networkd-link.h" #include "time-util.h" +#define NETDEV_COMMON_SECTIONS "Match\0NetDev\0" +/* This is the list of known sections. We need to ignore them in the initial parsing phase. */ +#define NETDEV_OTHER_SECTIONS \ + "-Bond\0" \ + "-Bridge\0" \ + "-FooOverUDP\0" \ + "-GENEVE\0" \ + "-IPVLAN\0" \ + "-IPVTAP\0" \ + "-L2TP\0" \ + "-L2TPSession\0" \ + "-MACsec\0" \ + "-MACsecReceiveChannel\0" \ + "-MACsecTransmitAssociation\0" \ + "-MACsecReceiveAssociation\0" \ + "-MACVTAP\0" \ + "-MACVLAN\0" \ + "-Tunnel\0" \ + "-Tun\0" \ + "-Tap\0" \ + "-Peer\0" \ + "-VLAN\0" \ + "-VRF\0" \ + "-VXCAN\0" \ + "-VXLAN\0" \ + "-WireGuard\0" \ + "-WireGuardPeer\0" \ + "-Xfrm\0" + typedef struct netdev_join_callback netdev_join_callback; struct netdev_join_callback { diff --git a/src/network/netdev/netdevsim.c b/src/network/netdev/netdevsim.c index 96f3932ccb..bfd2a16035 100644 --- a/src/network/netdev/netdevsim.c +++ b/src/network/netdev/netdevsim.c @@ -4,7 +4,7 @@ const NetDevVTable netdevsim_vtable = { .object_size = sizeof(NetDevSim), - .sections = "Match\0NetDev\0", + .sections = NETDEV_COMMON_SECTIONS, .create_type = NETDEV_CREATE_INDEPENDENT, .generate_mac = true, }; diff --git a/src/network/netdev/nlmon.c b/src/network/netdev/nlmon.c index 3a6179f503..30e49a55ab 100644 --- a/src/network/netdev/nlmon.c +++ b/src/network/netdev/nlmon.c @@ -16,7 +16,7 @@ static int netdev_nlmon_verify(NetDev *netdev, const char *filename) { const NetDevVTable nlmon_vtable = { .object_size = sizeof(NLMon), - .sections = "Match\0NetDev\0", + .sections = NETDEV_COMMON_SECTIONS, .create_type = NETDEV_CREATE_INDEPENDENT, .config_verify = netdev_nlmon_verify, }; diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c index 8b79051ef5..8b0e3d27ea 100644 --- a/src/network/netdev/tunnel.c +++ b/src/network/netdev/tunnel.c @@ -805,7 +805,7 @@ static void ip6tnl_init(NetDev *n) { const NetDevVTable ipip_vtable = { .object_size = sizeof(Tunnel), .init = ipip_sit_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_ipip_sit_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -815,7 +815,7 @@ const NetDevVTable ipip_vtable = { const NetDevVTable sit_vtable = { .object_size = sizeof(Tunnel), .init = ipip_sit_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_ipip_sit_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -825,7 +825,7 @@ const NetDevVTable sit_vtable = { const NetDevVTable vti_vtable = { .object_size = sizeof(Tunnel), .init = vti_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_vti_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -835,7 +835,7 @@ const NetDevVTable vti_vtable = { const NetDevVTable vti6_vtable = { .object_size = sizeof(Tunnel), .init = vti_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_vti_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -845,7 +845,7 @@ const NetDevVTable vti6_vtable = { const NetDevVTable gre_vtable = { .object_size = sizeof(Tunnel), .init = gre_erspan_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_gre_erspan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -855,7 +855,7 @@ const NetDevVTable gre_vtable = { const NetDevVTable gretap_vtable = { .object_size = sizeof(Tunnel), .init = gre_erspan_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_gre_erspan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -865,7 +865,7 @@ const NetDevVTable gretap_vtable = { const NetDevVTable ip6gre_vtable = { .object_size = sizeof(Tunnel), .init = ip6gre_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_ip6gre_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -875,7 +875,7 @@ const NetDevVTable ip6gre_vtable = { const NetDevVTable ip6gretap_vtable = { .object_size = sizeof(Tunnel), .init = ip6gre_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_ip6gre_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -885,7 +885,7 @@ const NetDevVTable ip6gretap_vtable = { const NetDevVTable ip6tnl_vtable = { .object_size = sizeof(Tunnel), .init = ip6tnl_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_ip6tnl_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, @@ -895,7 +895,7 @@ const NetDevVTable ip6tnl_vtable = { const NetDevVTable erspan_vtable = { .object_size = sizeof(Tunnel), .init = gre_erspan_init, - .sections = "Match\0NetDev\0Tunnel\0", + .sections = NETDEV_COMMON_SECTIONS "Tunnel\0", .fill_message_create = netdev_gre_erspan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_tunnel_verify, diff --git a/src/network/netdev/tuntap.c b/src/network/netdev/tuntap.c index ce69ef4124..aef72e7bbb 100644 --- a/src/network/netdev/tuntap.c +++ b/src/network/netdev/tuntap.c @@ -147,7 +147,7 @@ static int tuntap_verify(NetDev *netdev, const char *filename) { const NetDevVTable tun_vtable = { .object_size = sizeof(TunTap), - .sections = "Match\0NetDev\0Tun\0", + .sections = NETDEV_COMMON_SECTIONS "Tun\0", .config_verify = tuntap_verify, .done = tuntap_done, .create = netdev_create_tuntap, @@ -156,7 +156,7 @@ const NetDevVTable tun_vtable = { const NetDevVTable tap_vtable = { .object_size = sizeof(TunTap), - .sections = "Match\0NetDev\0Tap\0", + .sections = NETDEV_COMMON_SECTIONS "Tap\0", .config_verify = tuntap_verify, .done = tuntap_done, .create = netdev_create_tuntap, diff --git a/src/network/netdev/vcan.c b/src/network/netdev/vcan.c index 9b3ab48f1a..9a0f87b1e1 100644 --- a/src/network/netdev/vcan.c +++ b/src/network/netdev/vcan.c @@ -4,7 +4,7 @@ const NetDevVTable vcan_vtable = { .object_size = sizeof(VCan), - .sections = "Match\0NetDev\0", + .sections = NETDEV_COMMON_SECTIONS, .create_type = NETDEV_CREATE_INDEPENDENT, .generate_mac = true, }; diff --git a/src/network/netdev/veth.c b/src/network/netdev/veth.c index 4ed9e81511..98bbe86819 100644 --- a/src/network/netdev/veth.c +++ b/src/network/netdev/veth.c @@ -85,7 +85,7 @@ static void veth_done(NetDev *n) { const NetDevVTable veth_vtable = { .object_size = sizeof(Veth), - .sections = "Match\0NetDev\0Peer\0", + .sections = NETDEV_COMMON_SECTIONS "Peer\0", .done = veth_done, .fill_message_create = netdev_veth_fill_message_create, .create_type = NETDEV_CREATE_INDEPENDENT, diff --git a/src/network/netdev/vlan.c b/src/network/netdev/vlan.c index 1b4e5bc2d3..902aa804ff 100644 --- a/src/network/netdev/vlan.c +++ b/src/network/netdev/vlan.c @@ -85,7 +85,7 @@ static void vlan_init(NetDev *netdev) { const NetDevVTable vlan_vtable = { .object_size = sizeof(VLan), .init = vlan_init, - .sections = "Match\0NetDev\0VLAN\0", + .sections = NETDEV_COMMON_SECTIONS "VLAN\0", .fill_message_create = netdev_vlan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_vlan_verify, diff --git a/src/network/netdev/vrf.c b/src/network/netdev/vrf.c index dc7a967230..a8ed3fadcb 100644 --- a/src/network/netdev/vrf.c +++ b/src/network/netdev/vrf.c @@ -25,7 +25,7 @@ static int netdev_vrf_fill_message_create(NetDev *netdev, Link *link, sd_netlink const NetDevVTable vrf_vtable = { .object_size = sizeof(Vrf), - .sections = "Match\0NetDev\0VRF\0", + .sections = NETDEV_COMMON_SECTIONS "VRF\0", .fill_message_create = netdev_vrf_fill_message_create, .create_type = NETDEV_CREATE_MASTER, .generate_mac = true, diff --git a/src/network/netdev/vxcan.c b/src/network/netdev/vxcan.c index d1c3f091c3..1a5786a0b7 100644 --- a/src/network/netdev/vxcan.c +++ b/src/network/netdev/vxcan.c @@ -65,7 +65,7 @@ static void vxcan_done(NetDev *n) { const NetDevVTable vxcan_vtable = { .object_size = sizeof(VxCan), - .sections = "Match\0NetDev\0VXCAN\0", + .sections = NETDEV_COMMON_SECTIONS "VXCAN\0", .done = vxcan_done, .fill_message_create = netdev_vxcan_fill_message_create, .create_type = NETDEV_CREATE_INDEPENDENT, diff --git a/src/network/netdev/vxlan.c b/src/network/netdev/vxlan.c index 92f6005dcd..ace3c5d2ed 100644 --- a/src/network/netdev/vxlan.c +++ b/src/network/netdev/vxlan.c @@ -371,7 +371,7 @@ static void vxlan_init(NetDev *netdev) { const NetDevVTable vxlan_vtable = { .object_size = sizeof(VxLan), .init = vxlan_init, - .sections = "Match\0NetDev\0VXLAN\0", + .sections = NETDEV_COMMON_SECTIONS "VXLAN\0", .fill_message_create = netdev_vxlan_fill_message_create, .create_type = NETDEV_CREATE_STACKED, .config_verify = netdev_vxlan_verify, diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index 4a1228584d..71ff41d574 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -967,7 +967,7 @@ static int wireguard_verify(NetDev *netdev, const char *filename) { const NetDevVTable wireguard_vtable = { .object_size = sizeof(Wireguard), - .sections = "Match\0NetDev\0WireGuard\0WireGuardPeer\0", + .sections = NETDEV_COMMON_SECTIONS "WireGuard\0WireGuardPeer\0", .post_create = netdev_wireguard_post_create, .init = wireguard_init, .done = wireguard_done, diff --git a/src/network/netdev/xfrm.c b/src/network/netdev/xfrm.c index 7157af4df3..ff8ff35689 100644 --- a/src/network/netdev/xfrm.c +++ b/src/network/netdev/xfrm.c @@ -27,7 +27,7 @@ static int xfrm_fill_message_create(NetDev *netdev, Link *link, sd_netlink_messa const NetDevVTable xfrm_vtable = { .object_size = sizeof(Xfrm), - .sections = "Match\0NetDev\0Xfrm\0", + .sections = NETDEV_COMMON_SECTIONS "Xfrm\0", .fill_message_create = xfrm_fill_message_create, .create_type = NETDEV_CREATE_STACKED }; -- cgit v1.2.1 From f4331d0db28c75d70f2e8e0c06cc84e5909b4088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 22 Nov 2019 11:59:11 +0100 Subject: shared/install: warn about unkown sections in unit files As in the previous commit, ignoring unkown sections means users may be confused easily. It is better to warn about misspellt section names. In this case, we are using a separate item table, so we'd ignore all those sections anyway, so we could list them with out the minus prefixes and the effect would be the same. But I think it's clearer to prefix them. --- src/shared/install.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index 14dfd331d5..5680660928 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1290,9 +1290,21 @@ static int unit_file_load( assert(c); r = config_parse(info->name, path, f, - NULL, + "Install\0" + "-Unit\0" + "-Automount\0" + "-Device\0" + "-Mount\0" + "-Path\0" + "-Scope\0" + "-Service\0" + "-Slice\0" + "-Socket\0" + "-Swap\0" + "-Target\0" + "-Timer\0", config_item_table_lookup, items, - CONFIG_PARSE_RELAXED|CONFIG_PARSE_ALLOW_INCLUDE, info); + CONFIG_PARSE_ALLOW_INCLUDE, info); if (r < 0) return log_debug_errno(r, "Failed to parse %s: %m", info->name); -- cgit v1.2.1