mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
network: make several functions static
This commit is contained in:
parent
d9940a3f8a
commit
74154c2e28
@ -25,6 +25,116 @@
|
|||||||
|
|
||||||
#define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U
|
#define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U
|
||||||
|
|
||||||
|
static const char * const route_type_table[__RTN_MAX] = {
|
||||||
|
[RTN_UNICAST] = "unicast",
|
||||||
|
[RTN_LOCAL] = "local",
|
||||||
|
[RTN_BROADCAST] = "broadcast",
|
||||||
|
[RTN_ANYCAST] = "anycast",
|
||||||
|
[RTN_MULTICAST] = "multicast",
|
||||||
|
[RTN_BLACKHOLE] = "blackhole",
|
||||||
|
[RTN_UNREACHABLE] = "unreachable",
|
||||||
|
[RTN_PROHIBIT] = "prohibit",
|
||||||
|
[RTN_THROW] = "throw",
|
||||||
|
[RTN_NAT] = "nat",
|
||||||
|
[RTN_XRESOLVE] = "xresolve",
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_cc(__RTN_MAX <= UCHAR_MAX);
|
||||||
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(route_type, int);
|
||||||
|
|
||||||
|
static const char * const route_scope_table[] = {
|
||||||
|
[RT_SCOPE_UNIVERSE] = "global",
|
||||||
|
[RT_SCOPE_SITE] = "site",
|
||||||
|
[RT_SCOPE_LINK] = "link",
|
||||||
|
[RT_SCOPE_HOST] = "host",
|
||||||
|
[RT_SCOPE_NOWHERE] = "nowhere",
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(route_scope, int);
|
||||||
|
|
||||||
|
#define ROUTE_SCOPE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("nowhere") + 1)
|
||||||
|
static const char *format_route_scope(int scope, char *buf, size_t size) {
|
||||||
|
const char *s;
|
||||||
|
char *p = buf;
|
||||||
|
|
||||||
|
s = route_scope_to_string(scope);
|
||||||
|
if (s)
|
||||||
|
strpcpy(&p, size, s);
|
||||||
|
else
|
||||||
|
strpcpyf(&p, size, "%d", scope);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * const route_table_table[] = {
|
||||||
|
[RT_TABLE_DEFAULT] = "default",
|
||||||
|
[RT_TABLE_MAIN] = "main",
|
||||||
|
[RT_TABLE_LOCAL] = "local",
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(route_table, int);
|
||||||
|
|
||||||
|
#define ROUTE_TABLE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("default") + 1)
|
||||||
|
static const char *format_route_table(int table, char *buf, size_t size) {
|
||||||
|
const char *s;
|
||||||
|
char *p = buf;
|
||||||
|
|
||||||
|
s = route_table_to_string(table);
|
||||||
|
if (s)
|
||||||
|
strpcpy(&p, size, s);
|
||||||
|
else
|
||||||
|
strpcpyf(&p, size, "%d", table);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * const route_protocol_table[] = {
|
||||||
|
[RTPROT_KERNEL] = "kernel",
|
||||||
|
[RTPROT_BOOT] = "boot",
|
||||||
|
[RTPROT_STATIC] = "static",
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(route_protocol, int);
|
||||||
|
|
||||||
|
static const char * const route_protocol_full_table[] = {
|
||||||
|
[RTPROT_REDIRECT] = "redirect",
|
||||||
|
[RTPROT_KERNEL] = "kernel",
|
||||||
|
[RTPROT_BOOT] = "boot",
|
||||||
|
[RTPROT_STATIC] = "static",
|
||||||
|
[RTPROT_GATED] = "gated",
|
||||||
|
[RTPROT_RA] = "ra",
|
||||||
|
[RTPROT_MRT] = "mrt",
|
||||||
|
[RTPROT_ZEBRA] = "zebra",
|
||||||
|
[RTPROT_BIRD] = "bird",
|
||||||
|
[RTPROT_DNROUTED] = "dnrouted",
|
||||||
|
[RTPROT_XORP] = "xorp",
|
||||||
|
[RTPROT_NTK] = "ntk",
|
||||||
|
[RTPROT_DHCP] = "dhcp",
|
||||||
|
[RTPROT_MROUTED] = "mrouted",
|
||||||
|
[RTPROT_BABEL] = "babel",
|
||||||
|
[RTPROT_BGP] = "bgp",
|
||||||
|
[RTPROT_ISIS] = "isis",
|
||||||
|
[RTPROT_OSPF] = "ospf",
|
||||||
|
[RTPROT_RIP] = "rip",
|
||||||
|
[RTPROT_EIGRP] = "eigrp",
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(route_protocol_full, int);
|
||||||
|
|
||||||
|
#define ROUTE_PROTOCOL_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("redirect") + 1)
|
||||||
|
static const char *format_route_protocol(int protocol, char *buf, size_t size) {
|
||||||
|
const char *s;
|
||||||
|
char *p = buf;
|
||||||
|
|
||||||
|
s = route_protocol_full_to_string(protocol);
|
||||||
|
if (s)
|
||||||
|
strpcpy(&p, size, s);
|
||||||
|
else
|
||||||
|
strpcpyf(&p, size, "%d", protocol);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned routes_max(void) {
|
static unsigned routes_max(void) {
|
||||||
static thread_local unsigned cached = 0;
|
static thread_local unsigned cached = 0;
|
||||||
|
|
||||||
@ -282,7 +392,7 @@ DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(
|
|||||||
route_compare_func,
|
route_compare_func,
|
||||||
route_free);
|
route_free);
|
||||||
|
|
||||||
bool route_equal(Route *r1, Route *r2) {
|
static bool route_equal(Route *r1, Route *r2) {
|
||||||
if (r1 == r2)
|
if (r1 == r2)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -292,7 +402,7 @@ bool route_equal(Route *r1, Route *r2) {
|
|||||||
return route_compare_func(r1, r2) == 0;
|
return route_compare_func(r1, r2) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int route_get(Link *link, Route *in, Route **ret) {
|
static int route_get(Link *link, Route *in, Route **ret) {
|
||||||
|
|
||||||
Route *existing;
|
Route *existing;
|
||||||
|
|
||||||
@ -362,11 +472,11 @@ static int route_add_internal(Link *link, Set **routes, Route *in, Route **ret)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int route_add_foreign(Link *link, Route *in, Route **ret) {
|
static int route_add_foreign(Link *link, Route *in, Route **ret) {
|
||||||
return route_add_internal(link, &link->routes_foreign, in, ret);
|
return route_add_internal(link, &link->routes_foreign, in, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int route_add(Link *link, Route *in, Route **ret) {
|
static int route_add(Link *link, Route *in, Route **ret) {
|
||||||
|
|
||||||
Route *route;
|
Route *route;
|
||||||
int r;
|
int r;
|
||||||
@ -585,7 +695,7 @@ int link_drop_routes(Link *link) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata) {
|
static int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata) {
|
||||||
Route *route = userdata;
|
Route *route = userdata;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -1378,113 +1488,6 @@ int network_add_default_route_on_device(Network *network) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const route_type_table[__RTN_MAX] = {
|
|
||||||
[RTN_UNICAST] = "unicast",
|
|
||||||
[RTN_LOCAL] = "local",
|
|
||||||
[RTN_BROADCAST] = "broadcast",
|
|
||||||
[RTN_ANYCAST] = "anycast",
|
|
||||||
[RTN_MULTICAST] = "multicast",
|
|
||||||
[RTN_BLACKHOLE] = "blackhole",
|
|
||||||
[RTN_UNREACHABLE] = "unreachable",
|
|
||||||
[RTN_PROHIBIT] = "prohibit",
|
|
||||||
[RTN_THROW] = "throw",
|
|
||||||
[RTN_NAT] = "nat",
|
|
||||||
[RTN_XRESOLVE] = "xresolve",
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_cc(__RTN_MAX <= UCHAR_MAX);
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(route_type, int);
|
|
||||||
|
|
||||||
static const char * const route_scope_table[] = {
|
|
||||||
[RT_SCOPE_UNIVERSE] = "global",
|
|
||||||
[RT_SCOPE_SITE] = "site",
|
|
||||||
[RT_SCOPE_LINK] = "link",
|
|
||||||
[RT_SCOPE_HOST] = "host",
|
|
||||||
[RT_SCOPE_NOWHERE] = "nowhere",
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(route_scope, int);
|
|
||||||
|
|
||||||
const char *format_route_scope(int scope, char *buf, size_t size) {
|
|
||||||
const char *s;
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
s = route_scope_to_string(scope);
|
|
||||||
if (s)
|
|
||||||
strpcpy(&p, size, s);
|
|
||||||
else
|
|
||||||
strpcpyf(&p, size, "%d", scope);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char * const route_table_table[] = {
|
|
||||||
[RT_TABLE_DEFAULT] = "default",
|
|
||||||
[RT_TABLE_MAIN] = "main",
|
|
||||||
[RT_TABLE_LOCAL] = "local",
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(route_table, int);
|
|
||||||
|
|
||||||
const char *format_route_table(int table, char *buf, size_t size) {
|
|
||||||
const char *s;
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
s = route_table_to_string(table);
|
|
||||||
if (s)
|
|
||||||
strpcpy(&p, size, s);
|
|
||||||
else
|
|
||||||
strpcpyf(&p, size, "%d", table);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char * const route_protocol_table[] = {
|
|
||||||
[RTPROT_KERNEL] = "kernel",
|
|
||||||
[RTPROT_BOOT] = "boot",
|
|
||||||
[RTPROT_STATIC] = "static",
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(route_protocol, int);
|
|
||||||
|
|
||||||
static const char * const route_protocol_full_table[] = {
|
|
||||||
[RTPROT_REDIRECT] = "redirect",
|
|
||||||
[RTPROT_KERNEL] = "kernel",
|
|
||||||
[RTPROT_BOOT] = "boot",
|
|
||||||
[RTPROT_STATIC] = "static",
|
|
||||||
[RTPROT_GATED] = "gated",
|
|
||||||
[RTPROT_RA] = "ra",
|
|
||||||
[RTPROT_MRT] = "mrt",
|
|
||||||
[RTPROT_ZEBRA] = "zebra",
|
|
||||||
[RTPROT_BIRD] = "bird",
|
|
||||||
[RTPROT_DNROUTED] = "dnrouted",
|
|
||||||
[RTPROT_XORP] = "xorp",
|
|
||||||
[RTPROT_NTK] = "ntk",
|
|
||||||
[RTPROT_DHCP] = "dhcp",
|
|
||||||
[RTPROT_MROUTED] = "mrouted",
|
|
||||||
[RTPROT_BABEL] = "babel",
|
|
||||||
[RTPROT_BGP] = "bgp",
|
|
||||||
[RTPROT_ISIS] = "isis",
|
|
||||||
[RTPROT_OSPF] = "ospf",
|
|
||||||
[RTPROT_RIP] = "rip",
|
|
||||||
[RTPROT_EIGRP] = "eigrp",
|
|
||||||
};
|
|
||||||
|
|
||||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(route_protocol_full, int);
|
|
||||||
|
|
||||||
const char *format_route_protocol(int protocol, char *buf, size_t size) {
|
|
||||||
const char *s;
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
s = route_protocol_full_to_string(protocol);
|
|
||||||
if (s)
|
|
||||||
strpcpy(&p, size, s);
|
|
||||||
else
|
|
||||||
strpcpyf(&p, size, "%d", protocol);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
int config_parse_gateway(
|
int config_parse_gateway(
|
||||||
const char *unit,
|
const char *unit,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
|
@ -68,6 +68,8 @@ extern const struct hash_ops route_hash_ops;
|
|||||||
|
|
||||||
int route_new(Route **ret);
|
int route_new(Route **ret);
|
||||||
Route *route_free(Route *route);
|
Route *route_free(Route *route);
|
||||||
|
DEFINE_NETWORK_SECTION_FUNCTIONS(Route, route_free);
|
||||||
|
|
||||||
int route_configure(Route *route, Link *link, link_netlink_message_handler_t callback, Route **ret);
|
int route_configure(Route *route, Link *link, link_netlink_message_handler_t callback, Route **ret);
|
||||||
int route_remove(Route *route, Link *link, link_netlink_message_handler_t callback);
|
int route_remove(Route *route, Link *link, link_netlink_message_handler_t callback);
|
||||||
|
|
||||||
@ -79,31 +81,10 @@ int link_deserialize_routes(Link *link, const char *routes);
|
|||||||
|
|
||||||
int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
|
int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
|
||||||
|
|
||||||
int route_get(Link *link, Route *in, Route **ret);
|
|
||||||
int route_add(Link *link, Route *in, Route **ret);
|
|
||||||
int route_add_foreign(Link *link, Route *in, Route **ret);
|
|
||||||
bool route_equal(Route *r1, Route *r2);
|
|
||||||
|
|
||||||
int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata);
|
|
||||||
|
|
||||||
DEFINE_NETWORK_SECTION_FUNCTIONS(Route, route_free);
|
|
||||||
|
|
||||||
int network_add_ipv4ll_route(Network *network);
|
int network_add_ipv4ll_route(Network *network);
|
||||||
int network_add_default_route_on_device(Network *network);
|
int network_add_default_route_on_device(Network *network);
|
||||||
void network_verify_routes(Network *network);
|
void network_verify_routes(Network *network);
|
||||||
|
|
||||||
const char* route_type_to_string(int t) _const_;
|
|
||||||
int route_type_from_string(const char *s) _pure_;
|
|
||||||
|
|
||||||
#define ROUTE_SCOPE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("nowhere") + 1)
|
|
||||||
const char *format_route_scope(int scope, char *buf, size_t size);
|
|
||||||
|
|
||||||
#define ROUTE_TABLE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("default") + 1)
|
|
||||||
const char *format_route_table(int table, char *buf, size_t size);
|
|
||||||
|
|
||||||
#define ROUTE_PROTOCOL_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("redirect") + 1)
|
|
||||||
const char *format_route_protocol(int protocol, char *buf, size_t size);
|
|
||||||
|
|
||||||
CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
|
CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
|
||||||
CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
|
CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
|
||||||
CONFIG_PARSER_PROTOTYPE(config_parse_destination);
|
CONFIG_PARSER_PROTOTYPE(config_parse_destination);
|
||||||
|
Loading…
Reference in New Issue
Block a user