Skip to content

Commit 65022cd

Browse files
committed
network,udev/net: add Kind= settings in [Match] section
This may be useful for writing .network or .link files matching with virtual interfaces. Closes systemd#22541.
1 parent 430f07f commit 65022cd

File tree

14 files changed

+53
-3
lines changed

14 files changed

+53
-3
lines changed

man/systemd.link.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@
178178
</listitem>
179179
</varlistentry>
180180

181+
<varlistentry id='kind'>
182+
<term><varname>Kind=</varname></term>
183+
<listitem>
184+
<para>A whitespace-separated list of shell-style globs matching the device kind, as exposed by
185+
<command>networkctl status <replaceable>INTERFACE</replaceable></command> or
186+
<command>ip -d link show <replaceable>INTERFACE</replaceable></command>. If the list is
187+
prefixed with a "!", the test is inverted. Some valid values are <literal>bond</literal>,
188+
<literal>bridge</literal>, <literal>gre</literal>, <literal>tun</literal>,
189+
<literal>veth</literal>. Valid kinds are given by netlink's <literal>IFLA_INFO_KIND</literal>
190+
attribute, so this is not comprehensive.
191+
</para>
192+
</listitem>
193+
</varlistentry>
194+
181195
<varlistentry id='property'>
182196
<term><varname>Property=</varname></term>
183197
<listitem>

man/systemd.network.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<xi:include href="systemd.link.xml" xpointer="path" />
8686
<xi:include href="systemd.link.xml" xpointer="driver" />
8787
<xi:include href="systemd.link.xml" xpointer="type" />
88+
<xi:include href="systemd.link.xml" xpointer="kind" />
8889
<xi:include href="systemd.link.xml" xpointer="property" />
8990

9091
<varlistentry>

src/libsystemd/sd-netlink/netlink-util.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,13 @@ int rtnl_get_link_info(
366366
int ifindex,
367367
unsigned short *ret_iftype,
368368
unsigned *ret_flags,
369+
char **ret_kind,
369370
struct hw_addr_data *ret_hw_addr,
370371
struct hw_addr_data *ret_permanent_hw_addr) {
371372

372373
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL;
373374
struct hw_addr_data addr = HW_ADDR_NULL, perm_addr = HW_ADDR_NULL;
375+
_cleanup_free_ char *kind = NULL;
374376
unsigned short iftype;
375377
unsigned flags;
376378
int r;
@@ -409,6 +411,19 @@ int rtnl_get_link_info(
409411
return r;
410412
}
411413

414+
if (ret_kind) {
415+
r = sd_netlink_message_enter_container(reply, IFLA_LINKINFO);
416+
if (r >= 0) {
417+
r = sd_netlink_message_read_string_strdup(reply, IFLA_INFO_KIND, &kind);
418+
if (r < 0 && r != -ENODATA)
419+
return r;
420+
421+
r = sd_netlink_message_exit_container(reply);
422+
if (r < 0)
423+
return r;
424+
}
425+
}
426+
412427
if (ret_hw_addr) {
413428
r = netlink_message_read_hw_addr(reply, IFLA_ADDRESS, &addr);
414429
if (r < 0 && r != -ENODATA)
@@ -425,6 +440,8 @@ int rtnl_get_link_info(
425440
*ret_iftype = iftype;
426441
if (ret_flags)
427442
*ret_flags = flags;
443+
if (ret_kind)
444+
*ret_kind = TAKE_PTR(kind);
428445
if (ret_hw_addr)
429446
*ret_hw_addr = addr;
430447
if (ret_permanent_hw_addr)

src/libsystemd/sd-netlink/netlink-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int rtnl_get_link_info(
9494
int ifindex,
9595
unsigned short *ret_iftype,
9696
unsigned *ret_flags,
97+
char **ret_kind,
9798
struct hw_addr_data *ret_hw_addr,
9899
struct hw_addr_data *ret_permanent_hw_addr);
99100

src/network/networkd-link.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ static int link_get_network(Link *link, Network **ret) {
11691169
&link->permanent_hw_addr,
11701170
link->driver,
11711171
link->iftype,
1172+
link->kind,
11721173
link->ifname,
11731174
link->alternative_names,
11741175
link->wlan_iftype,

src/network/networkd-network-gperf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Match.PermanentMACAddress, config_parse_hw_addrs,
5252
Match.Path, config_parse_match_strv, 0, offsetof(Network, match.path)
5353
Match.Driver, config_parse_match_strv, 0, offsetof(Network, match.driver)
5454
Match.Type, config_parse_match_strv, 0, offsetof(Network, match.iftype)
55+
Match.Kind, config_parse_match_strv, 0, offsetof(Network, match.kind)
5556
Match.WLANInterfaceType, config_parse_match_strv, 0, offsetof(Network, match.wlan_iftype)
5657
Match.SSID, config_parse_match_strv, 0, offsetof(Network, match.ssid)
5758
Match.BSSID, config_parse_ether_addrs, 0, offsetof(Network, match.bssid)

src/shared/net-condition.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void net_match_clear(NetMatch *match) {
2222
match->path = strv_free(match->path);
2323
match->driver = strv_free(match->driver);
2424
match->iftype = strv_free(match->iftype);
25+
match->kind = strv_free(match->kind);
2526
match->ifname = strv_free(match->ifname);
2627
match->property = strv_free(match->property);
2728
match->wlan_iftype = strv_free(match->wlan_iftype);
@@ -38,6 +39,7 @@ bool net_match_is_empty(const NetMatch *match) {
3839
strv_isempty(match->path) &&
3940
strv_isempty(match->driver) &&
4041
strv_isempty(match->iftype) &&
42+
strv_isempty(match->kind) &&
4143
strv_isempty(match->ifname) &&
4244
strv_isempty(match->property) &&
4345
strv_isempty(match->wlan_iftype) &&
@@ -126,6 +128,7 @@ int net_match_config(
126128
const struct hw_addr_data *permanent_hw_addr,
127129
const char *driver,
128130
unsigned short iftype,
131+
const char *kind,
129132
const char *ifname,
130133
char * const *alternative_names,
131134
enum nl80211_iftype wlan_iftype,
@@ -160,6 +163,9 @@ int net_match_config(
160163
if (!net_condition_test_strv(match->iftype, iftype_str))
161164
return false;
162165

166+
if (!net_condition_test_strv(match->kind, kind))
167+
return false;
168+
163169
if (!net_condition_test_ifname(match->ifname, ifname, alternative_names))
164170
return false;
165171

src/shared/net-condition.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ typedef struct NetMatch {
1515
Set *permanent_hw_addr;
1616
char **path;
1717
char **driver;
18-
char **iftype;
18+
char **iftype; /* udev's DEVTYPE field or ARPHRD_XXX, e.g. ether, wlan. */
19+
char **kind; /* IFLA_INFO_KIND attribute, e.g. gre, gretap, erspan. */
1920
char **ifname;
2021
char **property;
2122
char **wlan_iftype;
@@ -33,6 +34,7 @@ int net_match_config(
3334
const struct hw_addr_data *permanent_hw_addr,
3435
const char *driver,
3536
unsigned short iftype,
37+
const char *kind,
3638
const char *ifname,
3739
char * const *alternative_names,
3840
enum nl80211_iftype wlan_iftype,

src/udev/net/link-config-gperf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Match.OriginalName, config_parse_match_ifnames,
2828
Match.Path, config_parse_match_strv, 0, offsetof(LinkConfig, match.path)
2929
Match.Driver, config_parse_match_strv, 0, offsetof(LinkConfig, match.driver)
3030
Match.Type, config_parse_match_strv, 0, offsetof(LinkConfig, match.iftype)
31+
Match.Kind, config_parse_match_strv, 0, offsetof(LinkConfig, match.kind)
3132
Match.Property, config_parse_match_property, 0, offsetof(LinkConfig, match.property)
3233
Match.Host, config_parse_net_condition, CONDITION_HOST, offsetof(LinkConfig, conditions)
3334
Match.Virtualization, config_parse_net_condition, CONDITION_VIRTUALIZATION, offsetof(LinkConfig, conditions)

src/udev/net/link-config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ Link *link_free(Link *link) {
361361
return NULL;
362362

363363
sd_device_unref(link->device);
364+
free(link->kind);
364365
free(link->driver);
365366
return mfree(link);
366367
}
@@ -402,7 +403,8 @@ int link_new(LinkConfigContext *ctx, sd_netlink **rtnl, sd_device *device, Link
402403
if (r < 0)
403404
log_link_debug_errno(link, r, "Failed to get \"addr_assign_type\" attribute, ignoring: %m");
404405

405-
r = rtnl_get_link_info(rtnl, link->ifindex, &link->iftype, &link->flags, &link->hw_addr, &link->permanent_hw_addr);
406+
r = rtnl_get_link_info(rtnl, link->ifindex, &link->iftype, &link->flags,
407+
&link->kind, &link->hw_addr, &link->permanent_hw_addr);
406408
if (r < 0)
407409
return r;
408410

@@ -439,6 +441,7 @@ int link_get_config(LinkConfigContext *ctx, Link *link) {
439441
&link->permanent_hw_addr,
440442
link->driver,
441443
link->iftype,
444+
link->kind,
442445
link->ifname,
443446
/* alternative_names = */ NULL,
444447
/* wlan_iftype = */ 0,

0 commit comments

Comments
 (0)