mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-02 02:38:03 +02:00
all: use nm_net_aux_rtnl_rtntype_{n2a,a2n}() helpers
This commit is contained in:
parent
0ef94bd1f0
commit
945612cc5d
5 changed files with 23 additions and 95 deletions
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "libnm-glib-aux/nm-c-list.h"
|
||||
|
||||
#include "libnm-base/nm-net-aux.h"
|
||||
#include "libnm-core-aux-intern/nm-common-macros.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-setting-connection.h"
|
||||
|
|
@ -1294,9 +1295,9 @@ nm_utils_ip_route_attribute_to_platform(int addr_family,
|
|||
|
||||
if ((variant = nm_ip_route_get_attribute(s_route, NM_IP_ROUTE_ATTRIBUTE_TYPE))
|
||||
&& g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
|
||||
guint8 type;
|
||||
int type;
|
||||
|
||||
type = nm_utils_route_type_by_name(g_variant_get_string(variant, NULL));
|
||||
type = nm_net_aux_rtnl_rtntype_a2n(g_variant_get_string(variant, NULL));
|
||||
nm_assert(NM_IN_SET(type, RTN_UNICAST, RTN_LOCAL));
|
||||
|
||||
r->type_coerced = nm_platform_route_type_coerce(type);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <linux/fib_rules.h>
|
||||
|
||||
#include "libnm-base/nm-net-aux.h"
|
||||
#include "libnm-glib-aux/nm-str-buf.h"
|
||||
#include "nm-setting-ip4-config.h"
|
||||
#include "nm-setting-ip6-config.h"
|
||||
|
|
@ -1385,7 +1386,7 @@ nm_ip_route_attribute_validate(const char *name,
|
|||
break;
|
||||
}
|
||||
case 'T': /* route type. */
|
||||
if (!NM_IN_SET(nm_utils_route_type_by_name(string), RTN_UNICAST, RTN_LOCAL)) {
|
||||
if (!NM_IN_SET(nm_net_aux_rtnl_rtntype_a2n(string), RTN_UNICAST, RTN_LOCAL)) {
|
||||
g_set_error(error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
|
|
@ -1432,10 +1433,14 @@ _nm_ip_route_attribute_validate_all(const NMIPRoute *route, GError **error)
|
|||
}
|
||||
|
||||
if ((val = g_hash_table_lookup(route->attributes, NM_IP_ROUTE_ATTRIBUTE_TYPE))) {
|
||||
nm_assert(g_variant_is_of_type(val, G_VARIANT_TYPE_STRING));
|
||||
u8 = nm_utils_route_type_by_name(g_variant_get_string(val, NULL));
|
||||
int v_i;
|
||||
|
||||
if (u8 == RTN_LOCAL && route->family == AF_INET
|
||||
nm_assert(g_variant_is_of_type(val, G_VARIANT_TYPE_STRING));
|
||||
|
||||
v_i = nm_net_aux_rtnl_rtntype_a2n(g_variant_get_string(val, NULL));
|
||||
nm_assert(v_i >= 0);
|
||||
|
||||
if (v_i == RTN_LOCAL && route->family == AF_INET
|
||||
&& (val = g_hash_table_lookup(route->attributes, NM_IP_ROUTE_ATTRIBUTE_SCOPE))) {
|
||||
nm_assert(g_variant_is_of_type(val, G_VARIANT_TYPE_BYTE));
|
||||
u8 = g_variant_get_byte(val);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
#include <glib-unix.h>
|
||||
#include <net/if.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
|
||||
#include "nm-errno.h"
|
||||
#include "nm-str-buf.h"
|
||||
|
|
@ -6114,33 +6113,3 @@ NM_ASSERT_VALID_PATH_COMPONENT(const char *name)
|
|||
NM_PRINT_FMT_QUOTED(name, "\"", name, "\"", "(null)"));
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(
|
||||
nm_utils_route_type_by_name,
|
||||
guint8,
|
||||
{ nm_assert(name); },
|
||||
{ return RTN_UNSPEC; },
|
||||
{"blackhole", RTN_BLACKHOLE},
|
||||
{"broadcast", RTN_BROADCAST},
|
||||
{"local", RTN_LOCAL},
|
||||
{"multicast", RTN_MULTICAST},
|
||||
{"nat", RTN_NAT},
|
||||
{"prohibit", RTN_PROHIBIT},
|
||||
{"throw", RTN_THROW},
|
||||
{"unicast", RTN_UNICAST},
|
||||
{"unreachable", RTN_UNREACHABLE}, );
|
||||
|
||||
NM_UTILS_ENUM2STR_DEFINE(nm_utils_route_type2str,
|
||||
guint8,
|
||||
NM_UTILS_ENUM2STR(RTN_BLACKHOLE, "blackhole"),
|
||||
NM_UTILS_ENUM2STR(RTN_BROADCAST, "broadcast"),
|
||||
NM_UTILS_ENUM2STR(RTN_LOCAL, "local"),
|
||||
NM_UTILS_ENUM2STR(RTN_MULTICAST, "multicast"),
|
||||
NM_UTILS_ENUM2STR(RTN_NAT, "nat"),
|
||||
NM_UTILS_ENUM2STR(RTN_PROHIBIT, "prohibit"),
|
||||
NM_UTILS_ENUM2STR(RTN_THROW, "throw"),
|
||||
NM_UTILS_ENUM2STR(RTN_UNICAST, "unicast"),
|
||||
NM_UTILS_ENUM2STR(RTN_UNREACHABLE, "unreachable"),
|
||||
NM_UTILS_ENUM2STR(RTN_UNSPEC, "unspecified"), );
|
||||
|
|
|
|||
|
|
@ -2768,10 +2768,4 @@ gboolean nm_utils_sysctl_ip_conf_is_path(int addr_family,
|
|||
const char *ifname,
|
||||
const char *property);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
guint8 nm_utils_route_type_by_name(const char *name);
|
||||
|
||||
const char *nm_utils_route_type2str(guint8 val, char *buf, gsize len);
|
||||
|
||||
#endif /* __NM_SHARED_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <linux/tc_act/tc_mirred.h>
|
||||
#include <libudev.h>
|
||||
|
||||
#include "libnm-base/nm-net-aux.h"
|
||||
#include "libnm-glib-aux/nm-dedup-multi.h"
|
||||
#include "libnm-glib-aux/nm-secret-utils.h"
|
||||
#include "libnm-glib-aux/nm-time-utils.h"
|
||||
|
|
@ -6434,9 +6435,8 @@ nm_platform_ip4_route_to_string(const NMPlatformIP4Route *route, char *buf, gsiz
|
|||
"%s" /* initrwnd */
|
||||
"%s" /* mtu */
|
||||
"",
|
||||
nm_utils_route_type2str(nm_platform_route_type_uncoerce(route->type_coerced),
|
||||
str_type,
|
||||
sizeof(str_type)),
|
||||
nm_net_aux_rtnl_rtntype_n2a_maybe_buf(nm_platform_route_type_uncoerce(route->type_coerced),
|
||||
str_type),
|
||||
route->table_any
|
||||
? "table ?? "
|
||||
: (route->table_coerced
|
||||
|
|
@ -6560,9 +6560,8 @@ nm_platform_ip6_route_to_string(const NMPlatformIP6Route *route, char *buf, gsiz
|
|||
"%s" /* mtu */
|
||||
"%s" /* pref */
|
||||
"",
|
||||
nm_utils_route_type2str(nm_platform_route_type_uncoerce(route->type_coerced),
|
||||
str_type,
|
||||
sizeof(str_type)),
|
||||
nm_net_aux_rtnl_rtntype_n2a_maybe_buf(nm_platform_route_type_uncoerce(route->type_coerced),
|
||||
str_type),
|
||||
route->table_any
|
||||
? "table ?? "
|
||||
: (route->table_coerced
|
||||
|
|
@ -6820,53 +6819,13 @@ nm_platform_routing_rule_to_string(const NMPlatformRoutingRule *routing_rule, ch
|
|||
if (NM_FLAGS_HAS(routing_rule->flags, FIB_RULE_UNRESOLVED))
|
||||
nm_utils_strbuf_append_str(&buf, &len, " unresolved");
|
||||
} else if (routing_rule->action != FR_ACT_TO_TBL) {
|
||||
const char *ss;
|
||||
char ss_buf[60];
|
||||
char ss_buf[60];
|
||||
|
||||
#define _V(v1, v2) ((sizeof(char[(((int) (v1)) == ((int) (v2))) ? 1 : -1]) * 0) + (v1))
|
||||
switch (routing_rule->action) {
|
||||
case _V(FR_ACT_UNSPEC, RTN_UNSPEC):
|
||||
ss = "none";
|
||||
break;
|
||||
case _V(FR_ACT_TO_TBL, RTN_UNICAST):
|
||||
ss = "unicast";
|
||||
break;
|
||||
case _V(FR_ACT_GOTO, RTN_LOCAL):
|
||||
ss = "local";
|
||||
break;
|
||||
case _V(FR_ACT_NOP, RTN_BROADCAST):
|
||||
ss = "nop";
|
||||
break;
|
||||
case _V(FR_ACT_RES3, RTN_ANYCAST):
|
||||
ss = "anycast";
|
||||
break;
|
||||
case _V(FR_ACT_RES4, RTN_MULTICAST):
|
||||
ss = "multicast";
|
||||
break;
|
||||
case _V(FR_ACT_BLACKHOLE, RTN_BLACKHOLE):
|
||||
ss = "blackhole";
|
||||
break;
|
||||
case _V(FR_ACT_UNREACHABLE, RTN_UNREACHABLE):
|
||||
ss = "unreachable";
|
||||
break;
|
||||
case _V(FR_ACT_PROHIBIT, RTN_PROHIBIT):
|
||||
ss = "prohibit";
|
||||
break;
|
||||
case RTN_THROW:
|
||||
ss = "throw";
|
||||
break;
|
||||
case RTN_NAT:
|
||||
ss = "nat";
|
||||
break;
|
||||
case RTN_XRESOLVE:
|
||||
ss = "xresolve";
|
||||
break;
|
||||
default:
|
||||
ss = nm_sprintf_buf(ss_buf, "action-%u", routing_rule->action);
|
||||
break;
|
||||
}
|
||||
#undef _V
|
||||
nm_utils_strbuf_append(&buf, &len, " %s", ss);
|
||||
nm_utils_strbuf_append(&buf,
|
||||
&len,
|
||||
" %s",
|
||||
nm_net_aux_rtnl_rtntype_n2a(routing_rule->action)
|
||||
?: nm_sprintf_buf(ss_buf, "action-%u", routing_rule->action));
|
||||
}
|
||||
|
||||
if (routing_rule->protocol != RTPROT_UNSPEC)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue