Merge pull request #15166 from ssahani/networkctl-ipvlan

networkctl: Add support to display ipvlan
This commit is contained in:
Lennart Poettering 2020-05-19 09:29:45 +02:00 committed by GitHub
commit 201fa8f256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 38 deletions

View file

@ -4,25 +4,11 @@
#include "conf-parser.h"
#include "ipvlan.h"
#include "ipvlan-util.h"
#include "networkd-link.h"
#include "string-table.h"
#include "string-util.h"
static const char* const ipvlan_mode_table[_NETDEV_IPVLAN_MODE_MAX] = {
[NETDEV_IPVLAN_MODE_L2] = "L2",
[NETDEV_IPVLAN_MODE_L3] = "L3",
[NETDEV_IPVLAN_MODE_L3S] = "L3S",
};
DEFINE_STRING_TABLE_LOOKUP(ipvlan_mode, IPVlanMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_mode, ipvlan_mode, IPVlanMode, "Failed to parse ipvlan mode");
static const char* const ipvlan_flags_table[_NETDEV_IPVLAN_FLAGS_MAX] = {
[NETDEV_IPVLAN_FLAGS_BRIGDE] = "bridge",
[NETDEV_IPVLAN_FLAGS_PRIVATE] = "private",
[NETDEV_IPVLAN_FLAGS_VEPA] = "vepa",
};
DEFINE_STRING_TABLE_LOOKUP(ipvlan_flags, IPVlanFlags);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_flags, ipvlan_flags, IPVlanFlags, "Failed to parse ipvlan flags");
static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {

View file

@ -4,24 +4,9 @@
#include <netinet/in.h>
#include <linux/if_link.h>
#include "ipvlan-util.h"
#include "netdev.h"
typedef enum IPVlanMode {
NETDEV_IPVLAN_MODE_L2 = IPVLAN_MODE_L2,
NETDEV_IPVLAN_MODE_L3 = IPVLAN_MODE_L3,
NETDEV_IPVLAN_MODE_L3S = IPVLAN_MODE_L3S,
_NETDEV_IPVLAN_MODE_MAX,
_NETDEV_IPVLAN_MODE_INVALID = -1
} IPVlanMode;
typedef enum IPVlanFlags {
NETDEV_IPVLAN_FLAGS_BRIGDE,
NETDEV_IPVLAN_FLAGS_PRIVATE = IPVLAN_F_PRIVATE,
NETDEV_IPVLAN_FLAGS_VEPA = IPVLAN_F_VEPA,
_NETDEV_IPVLAN_FLAGS_MAX,
_NETDEV_IPVLAN_FLAGS_INVALID = -1
} IPVlanFlags;
typedef struct IPVlan {
NetDev meta;
@ -34,12 +19,6 @@ DEFINE_NETDEV_CAST(IPVTAP, IPVlan);
extern const NetDevVTable ipvlan_vtable;
extern const NetDevVTable ipvtap_vtable;
const char *ipvlan_mode_to_string(IPVlanMode d) _const_;
IPVlanMode ipvlan_mode_from_string(const char *d) _pure_;
const char *ipvlan_flags_to_string(IPVlanFlags d) _const_;
IPVlanFlags ipvlan_flags_from_string(const char *d) _pure_;
CONFIG_PARSER_PROTOTYPE(config_parse_ipvlan_mode);
CONFIG_PARSER_PROTOTYPE(config_parse_ipvlan_flags);

View file

@ -33,6 +33,7 @@
#include "geneve-util.h"
#include "glob-util.h"
#include "hwdb-util.h"
#include "ipvlan-util.h"
#include "local-addresses.h"
#include "locale-util.h"
#include "logs-show.h"
@ -192,6 +193,10 @@ typedef struct LinkInfo {
/* macvlan and macvtap info */
uint32_t macvlan_mode;
/* ipvlan info */
uint16_t ipvlan_mode;
uint16_t ipvlan_flags;
/* ethtool info */
int autonegotiation;
uint64_t speed;
@ -335,6 +340,10 @@ static int decode_netdev(sd_netlink_message *m, LinkInfo *info) {
(void) sd_netlink_message_read_in6_addr(m, IFLA_VTI_REMOTE, &info->remote.in6);
} else if (STR_IN_SET(received_kind, "macvlan", "macvtap"))
(void) sd_netlink_message_read_u32(m, IFLA_MACVLAN_MODE, &info->macvlan_mode);
else if (streq(received_kind, "ipvlan")) {
(void) sd_netlink_message_read_u16(m, IFLA_IPVLAN_MODE, &info->ipvlan_mode);
(void) sd_netlink_message_read_u16(m, IFLA_IPVLAN_FLAGS, &info->ipvlan_flags);
}
strncpy(info->netdev_kind, received_kind, IFNAMSIZ);
@ -1798,6 +1807,28 @@ static int link_status_one(
TABLE_STRING, macvlan_mode_to_string(info->macvlan_mode));
if (r < 0)
return table_log_add_error(r);
} else if (streq_ptr(info->netdev_kind, "ipvlan")) {
_cleanup_free_ char *p = NULL, *s = NULL;
if (info->ipvlan_flags & IPVLAN_F_PRIVATE)
p = strdup("private");
else if (info->ipvlan_flags & IPVLAN_F_VEPA)
p = strdup("vepa");
else
p = strdup("bridge");
if (!p)
log_oom();
s = strjoin(ipvlan_mode_to_string(info->ipvlan_mode), " (", p, ")");
if (!s)
return log_oom();
r = table_add_many(table,
TABLE_EMPTY,
TABLE_STRING, "Mode:",
TABLE_STRING, s);
if (r < 0)
return table_log_add_error(r);
}
if (info->has_wlan_link_info) {

22
src/shared/ipvlan-util.c Normal file
View file

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <net/if.h>
#include "ipvlan-util.h"
#include "string-table.h"
static const char* const ipvlan_mode_table[_NETDEV_IPVLAN_MODE_MAX] = {
[NETDEV_IPVLAN_MODE_L2] = "L2",
[NETDEV_IPVLAN_MODE_L3] = "L3",
[NETDEV_IPVLAN_MODE_L3S] = "L3S",
};
DEFINE_STRING_TABLE_LOOKUP(ipvlan_mode, IPVlanMode);
static const char* const ipvlan_flags_table[_NETDEV_IPVLAN_FLAGS_MAX] = {
[NETDEV_IPVLAN_FLAGS_BRIGDE] = "bridge",
[NETDEV_IPVLAN_FLAGS_PRIVATE] = "private",
[NETDEV_IPVLAN_FLAGS_VEPA] = "vepa",
};
DEFINE_STRING_TABLE_LOOKUP(ipvlan_flags, IPVlanFlags);

29
src/shared/ipvlan-util.h Normal file
View file

@ -0,0 +1,29 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <netinet/in.h>
#include <linux/if_link.h>
#include "macro.h"
typedef enum IPVlanMode {
NETDEV_IPVLAN_MODE_L2 = IPVLAN_MODE_L2,
NETDEV_IPVLAN_MODE_L3 = IPVLAN_MODE_L3,
NETDEV_IPVLAN_MODE_L3S = IPVLAN_MODE_L3S,
_NETDEV_IPVLAN_MODE_MAX,
_NETDEV_IPVLAN_MODE_INVALID = -1
} IPVlanMode;
typedef enum IPVlanFlags {
NETDEV_IPVLAN_FLAGS_BRIGDE,
NETDEV_IPVLAN_FLAGS_PRIVATE = IPVLAN_F_PRIVATE,
NETDEV_IPVLAN_FLAGS_VEPA = IPVLAN_F_VEPA,
_NETDEV_IPVLAN_FLAGS_MAX,
_NETDEV_IPVLAN_FLAGS_INVALID = -1
} IPVlanFlags;
const char *ipvlan_mode_to_string(IPVlanMode d) _const_;
IPVlanMode ipvlan_mode_from_string(const char *d) _pure_;
const char *ipvlan_flags_to_string(IPVlanFlags d) _const_;
IPVlanFlags ipvlan_flags_from_string(const char *d) _pure_;

View file

@ -120,6 +120,8 @@ shared_sources = files('''
install-printf.h
install.c
install.h
ipvlan-util.c
ipvlan-util.h
ip-protocol-list.c
ip-protocol-list.h
journal-importer.c