mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
network: merge RequestType and SetLinkOperation
These two enum indicate how we process the request. Hence, it is not necessary to introduce two separated indicators.
This commit is contained in:
parent
a48ffe47cf
commit
eb93dc9bde
@ -18,6 +18,7 @@
|
||||
#include "networkd-queue.h"
|
||||
#include "networkd-setlink.h"
|
||||
#include "qdisc.h"
|
||||
#include "string-table.h"
|
||||
#include "tclass.h"
|
||||
|
||||
static void request_free_object(RequestType type, void *object) {
|
||||
@ -63,7 +64,17 @@ static void request_free_object(RequestType type, void *object) {
|
||||
case REQUEST_TYPE_ROUTING_POLICY_RULE:
|
||||
routing_policy_rule_free(object);
|
||||
break;
|
||||
case REQUEST_TYPE_SET_LINK:
|
||||
case REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE:
|
||||
case REQUEST_TYPE_SET_LINK_BOND:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE_VLAN:
|
||||
case REQUEST_TYPE_SET_LINK_CAN:
|
||||
case REQUEST_TYPE_SET_LINK_FLAGS:
|
||||
case REQUEST_TYPE_SET_LINK_GROUP:
|
||||
case REQUEST_TYPE_SET_LINK_IPOIB:
|
||||
case REQUEST_TYPE_SET_LINK_MAC:
|
||||
case REQUEST_TYPE_SET_LINK_MASTER:
|
||||
case REQUEST_TYPE_SET_LINK_MTU:
|
||||
break;
|
||||
case REQUEST_TYPE_TC_QDISC:
|
||||
qdisc_free(object);
|
||||
@ -166,8 +177,17 @@ static void request_hash_func(const Request *req, struct siphash *state) {
|
||||
case REQUEST_TYPE_ROUTING_POLICY_RULE:
|
||||
routing_policy_rule_hash_func(req->rule, state);
|
||||
break;
|
||||
case REQUEST_TYPE_SET_LINK:
|
||||
trivial_hash_func(req->set_link_operation_ptr, state);
|
||||
case REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE:
|
||||
case REQUEST_TYPE_SET_LINK_BOND:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE_VLAN:
|
||||
case REQUEST_TYPE_SET_LINK_CAN:
|
||||
case REQUEST_TYPE_SET_LINK_FLAGS:
|
||||
case REQUEST_TYPE_SET_LINK_GROUP:
|
||||
case REQUEST_TYPE_SET_LINK_IPOIB:
|
||||
case REQUEST_TYPE_SET_LINK_MAC:
|
||||
case REQUEST_TYPE_SET_LINK_MASTER:
|
||||
case REQUEST_TYPE_SET_LINK_MTU:
|
||||
break;
|
||||
case REQUEST_TYPE_TC_QDISC:
|
||||
qdisc_hash_func(req->qdisc, state);
|
||||
@ -231,8 +251,18 @@ static int request_compare_func(const struct Request *a, const struct Request *b
|
||||
return 0;
|
||||
case REQUEST_TYPE_ROUTING_POLICY_RULE:
|
||||
return routing_policy_rule_compare_func(a->rule, b->rule);
|
||||
case REQUEST_TYPE_SET_LINK:
|
||||
return trivial_compare_func(a->set_link_operation_ptr, b->set_link_operation_ptr);
|
||||
case REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE:
|
||||
case REQUEST_TYPE_SET_LINK_BOND:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE_VLAN:
|
||||
case REQUEST_TYPE_SET_LINK_CAN:
|
||||
case REQUEST_TYPE_SET_LINK_FLAGS:
|
||||
case REQUEST_TYPE_SET_LINK_GROUP:
|
||||
case REQUEST_TYPE_SET_LINK_IPOIB:
|
||||
case REQUEST_TYPE_SET_LINK_MAC:
|
||||
case REQUEST_TYPE_SET_LINK_MASTER:
|
||||
case REQUEST_TYPE_SET_LINK_MTU:
|
||||
return 0;
|
||||
case REQUEST_TYPE_TC_QDISC:
|
||||
return qdisc_compare_func(a->qdisc, b->qdisc);
|
||||
case REQUEST_TYPE_TC_CLASS:
|
||||
@ -317,7 +347,17 @@ int link_queue_request(
|
||||
REQUEST_TYPE_DHCP6_CLIENT,
|
||||
REQUEST_TYPE_NDISC,
|
||||
REQUEST_TYPE_RADV,
|
||||
REQUEST_TYPE_SET_LINK,
|
||||
REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE,
|
||||
REQUEST_TYPE_SET_LINK_BOND,
|
||||
REQUEST_TYPE_SET_LINK_BRIDGE,
|
||||
REQUEST_TYPE_SET_LINK_BRIDGE_VLAN,
|
||||
REQUEST_TYPE_SET_LINK_CAN,
|
||||
REQUEST_TYPE_SET_LINK_FLAGS,
|
||||
REQUEST_TYPE_SET_LINK_GROUP,
|
||||
REQUEST_TYPE_SET_LINK_IPOIB,
|
||||
REQUEST_TYPE_SET_LINK_MAC,
|
||||
REQUEST_TYPE_SET_LINK_MASTER,
|
||||
REQUEST_TYPE_SET_LINK_MTU,
|
||||
REQUEST_TYPE_UP_DOWN) ||
|
||||
object);
|
||||
assert(IN_SET(type,
|
||||
@ -430,8 +470,18 @@ int manager_process_requests(sd_event_source *s, void *userdata) {
|
||||
case REQUEST_TYPE_ROUTING_POLICY_RULE:
|
||||
r = routing_policy_rule_process_request(req, req->link, req->rule);
|
||||
break;
|
||||
case REQUEST_TYPE_SET_LINK:
|
||||
r = request_process_set_link(req);
|
||||
case REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE:
|
||||
case REQUEST_TYPE_SET_LINK_BOND:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE_VLAN:
|
||||
case REQUEST_TYPE_SET_LINK_CAN:
|
||||
case REQUEST_TYPE_SET_LINK_FLAGS:
|
||||
case REQUEST_TYPE_SET_LINK_GROUP:
|
||||
case REQUEST_TYPE_SET_LINK_IPOIB:
|
||||
case REQUEST_TYPE_SET_LINK_MAC:
|
||||
case REQUEST_TYPE_SET_LINK_MASTER:
|
||||
case REQUEST_TYPE_SET_LINK_MTU:
|
||||
r = link_process_set_link(req, req->link, NULL);
|
||||
break;
|
||||
case REQUEST_TYPE_TC_QDISC:
|
||||
r = qdisc_process_request(req, req->link, NULL);
|
||||
@ -494,3 +544,39 @@ int request_call_netlink_async(sd_netlink *nl, sd_netlink_message *m, Request *r
|
||||
request_ref(req);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *const request_type_table[_REQUEST_TYPE_MAX] = {
|
||||
[REQUEST_TYPE_ACTIVATE_LINK] = "activate link",
|
||||
[REQUEST_TYPE_ADDRESS] = "address",
|
||||
[REQUEST_TYPE_ADDRESS_LABEL] = "address label",
|
||||
[REQUEST_TYPE_BRIDGE_FDB] = "bridge FDB",
|
||||
[REQUEST_TYPE_BRIDGE_MDB] = "bridge MDB",
|
||||
[REQUEST_TYPE_DHCP_SERVER] = "DHCP server",
|
||||
[REQUEST_TYPE_DHCP4_CLIENT] = "DHCPv4 client",
|
||||
[REQUEST_TYPE_DHCP6_CLIENT] = "DHCPv6 client",
|
||||
[REQUEST_TYPE_IPV6_PROXY_NDP] = "IPv6 proxy NDP",
|
||||
[REQUEST_TYPE_NDISC] = "NDisc",
|
||||
[REQUEST_TYPE_NEIGHBOR] = "neighbor",
|
||||
[REQUEST_TYPE_NETDEV_INDEPENDENT] = "independent netdev",
|
||||
[REQUEST_TYPE_NETDEV_STACKED] = "stacked netdev",
|
||||
[REQUEST_TYPE_NEXTHOP] = "nexthop",
|
||||
[REQUEST_TYPE_RADV] = "RADV",
|
||||
[REQUEST_TYPE_ROUTE] = "route",
|
||||
[REQUEST_TYPE_ROUTING_POLICY_RULE] = "routing policy rule",
|
||||
[REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE] = "IPv6LL address generation mode",
|
||||
[REQUEST_TYPE_SET_LINK_BOND] = "bond configurations",
|
||||
[REQUEST_TYPE_SET_LINK_BRIDGE] = "bridge configurations",
|
||||
[REQUEST_TYPE_SET_LINK_BRIDGE_VLAN] = "bridge VLAN configurations",
|
||||
[REQUEST_TYPE_SET_LINK_CAN] = "CAN interface configurations",
|
||||
[REQUEST_TYPE_SET_LINK_FLAGS] = "link flags",
|
||||
[REQUEST_TYPE_SET_LINK_GROUP] = "interface group",
|
||||
[REQUEST_TYPE_SET_LINK_IPOIB] = "IPoIB configurations",
|
||||
[REQUEST_TYPE_SET_LINK_MAC] = "MAC address",
|
||||
[REQUEST_TYPE_SET_LINK_MASTER] = "master interface",
|
||||
[REQUEST_TYPE_SET_LINK_MTU] = "MTU",
|
||||
[REQUEST_TYPE_TC_QDISC] = "QDisc",
|
||||
[REQUEST_TYPE_TC_CLASS] = "TClass",
|
||||
[REQUEST_TYPE_UP_DOWN] = "bring link up or down",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_TO_STRING(request_type, RequestType);
|
||||
|
@ -39,7 +39,17 @@ typedef enum RequestType {
|
||||
REQUEST_TYPE_RADV,
|
||||
REQUEST_TYPE_ROUTE,
|
||||
REQUEST_TYPE_ROUTING_POLICY_RULE,
|
||||
REQUEST_TYPE_SET_LINK,
|
||||
REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE, /* Setting IPv6LL address generation mode. */
|
||||
REQUEST_TYPE_SET_LINK_BOND, /* Setting bond configs. */
|
||||
REQUEST_TYPE_SET_LINK_BRIDGE, /* Setting bridge configs. */
|
||||
REQUEST_TYPE_SET_LINK_BRIDGE_VLAN, /* Setting bridge VLAN configs. */
|
||||
REQUEST_TYPE_SET_LINK_CAN, /* Setting CAN interface configs. */
|
||||
REQUEST_TYPE_SET_LINK_FLAGS, /* Setting IFF_NOARP or friends. */
|
||||
REQUEST_TYPE_SET_LINK_GROUP, /* Setting interface group. */
|
||||
REQUEST_TYPE_SET_LINK_IPOIB, /* Setting IPoIB configs. */
|
||||
REQUEST_TYPE_SET_LINK_MAC, /* Setting MAC address. */
|
||||
REQUEST_TYPE_SET_LINK_MASTER, /* Setting IFLA_MASTER. */
|
||||
REQUEST_TYPE_SET_LINK_MTU, /* Setting MTU. */
|
||||
REQUEST_TYPE_TC_CLASS,
|
||||
REQUEST_TYPE_TC_QDISC,
|
||||
REQUEST_TYPE_UP_DOWN,
|
||||
@ -103,3 +113,5 @@ int link_queue_request(
|
||||
|
||||
int manager_process_requests(sd_event_source *s, void *userdata);
|
||||
int request_call_netlink_async(sd_netlink *nl, sd_netlink_message *m, Request *req);
|
||||
|
||||
const char* request_type_to_string(RequestType t) _const_;
|
||||
|
@ -14,23 +14,6 @@
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-queue.h"
|
||||
#include "networkd-setlink.h"
|
||||
#include "string-table.h"
|
||||
|
||||
static const char *const set_link_operation_table[_SET_LINK_OPERATION_MAX] = {
|
||||
[SET_LINK_ADDRESS_GENERATION_MODE] = "IPv6LL address generation mode",
|
||||
[SET_LINK_BOND] = "bond configurations",
|
||||
[SET_LINK_BRIDGE] = "bridge configurations",
|
||||
[SET_LINK_BRIDGE_VLAN] = "bridge VLAN configurations",
|
||||
[SET_LINK_CAN] = "CAN interface configurations",
|
||||
[SET_LINK_FLAGS] = "link flags",
|
||||
[SET_LINK_GROUP] = "interface group",
|
||||
[SET_LINK_IPOIB] = "IPoIB configurations",
|
||||
[SET_LINK_MAC] = "MAC address",
|
||||
[SET_LINK_MASTER] = "master interface",
|
||||
[SET_LINK_MTU] = "MTU",
|
||||
};
|
||||
|
||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(set_link_operation, SetLinkOperation);
|
||||
|
||||
static int get_link_default_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
return link_getlink_handler_internal(rtnl, m, link, "Failed to sync link information");
|
||||
@ -59,20 +42,17 @@ static int set_link_handler_internal(
|
||||
bool ignore,
|
||||
link_netlink_message_handler_t get_link_handler) {
|
||||
|
||||
SetLinkOperation op;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(req);
|
||||
assert(link);
|
||||
|
||||
op = PTR_TO_INT(req->set_link_operation_ptr);
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0) {
|
||||
const char *error_msg;
|
||||
|
||||
error_msg = strjoina("Failed to set ", set_link_operation_to_string(op), ignore ? ", ignoring" : "");
|
||||
error_msg = strjoina("Failed to set ", request_type_to_string(req->type), ignore ? ", ignoring" : "");
|
||||
log_link_message_warning_errno(link, m, r, error_msg);
|
||||
|
||||
if (!ignore)
|
||||
@ -80,7 +60,7 @@ static int set_link_handler_internal(
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_link_debug(link, "%s set.", set_link_operation_to_string(op));
|
||||
log_link_debug(link, "%s set.", request_type_to_string(req->type));
|
||||
|
||||
if (get_link_handler) {
|
||||
r = link_call_getlink(link, get_link_handler);
|
||||
@ -196,17 +176,17 @@ static int link_set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, Request
|
||||
static int link_configure_fill_message(
|
||||
Link *link,
|
||||
sd_netlink_message *req,
|
||||
SetLinkOperation op,
|
||||
RequestType type,
|
||||
void *userdata) {
|
||||
int r;
|
||||
|
||||
switch (op) {
|
||||
case SET_LINK_ADDRESS_GENERATION_MODE:
|
||||
switch (type) {
|
||||
case REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE:
|
||||
r = ipv6ll_addrgen_mode_fill_message(req, PTR_TO_UINT8(userdata));
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
case SET_LINK_BOND:
|
||||
case REQUEST_TYPE_SET_LINK_BOND:
|
||||
r = sd_netlink_message_set_flags(req, NLM_F_REQUEST | NLM_F_ACK);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -240,7 +220,7 @@ static int link_configure_fill_message(
|
||||
return r;
|
||||
|
||||
break;
|
||||
case SET_LINK_BRIDGE:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE:
|
||||
r = sd_rtnl_message_link_set_family(req, AF_BRIDGE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -343,7 +323,7 @@ static int link_configure_fill_message(
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
case SET_LINK_BRIDGE_VLAN:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE_VLAN:
|
||||
r = sd_rtnl_message_link_set_family(req, AF_BRIDGE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -368,12 +348,12 @@ static int link_configure_fill_message(
|
||||
return r;
|
||||
|
||||
break;
|
||||
case SET_LINK_CAN:
|
||||
case REQUEST_TYPE_SET_LINK_CAN:
|
||||
r = can_set_netlink_message(link, req);
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
case SET_LINK_FLAGS: {
|
||||
case REQUEST_TYPE_SET_LINK_FLAGS: {
|
||||
unsigned ifi_change = 0, ifi_flags = 0;
|
||||
|
||||
if (link->network->arp >= 0) {
|
||||
@ -402,27 +382,27 @@ static int link_configure_fill_message(
|
||||
|
||||
break;
|
||||
}
|
||||
case SET_LINK_GROUP:
|
||||
case REQUEST_TYPE_SET_LINK_GROUP:
|
||||
r = sd_netlink_message_append_u32(req, IFLA_GROUP, (uint32_t) link->network->group);
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
case SET_LINK_MAC:
|
||||
case REQUEST_TYPE_SET_LINK_MAC:
|
||||
r = netlink_message_append_hw_addr(req, IFLA_ADDRESS, &link->requested_hw_addr);
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
case SET_LINK_IPOIB:
|
||||
case REQUEST_TYPE_SET_LINK_IPOIB:
|
||||
r = ipoib_set_netlink_message(link, req);
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
case SET_LINK_MASTER:
|
||||
case REQUEST_TYPE_SET_LINK_MASTER:
|
||||
r = sd_netlink_message_append_u32(req, IFLA_MASTER, PTR_TO_UINT32(userdata));
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
case SET_LINK_MTU:
|
||||
case REQUEST_TYPE_SET_LINK_MTU:
|
||||
r = sd_netlink_message_append_u32(req, IFLA_MTU, PTR_TO_UINT32(userdata));
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -436,7 +416,6 @@ static int link_configure_fill_message(
|
||||
|
||||
static int link_configure(Link *link, Request *req) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
|
||||
SetLinkOperation op;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -444,20 +423,18 @@ static int link_configure(Link *link, Request *req) {
|
||||
assert(link->manager->rtnl);
|
||||
assert(req);
|
||||
|
||||
op = PTR_TO_INT(req->set_link_operation_ptr);
|
||||
log_link_debug(link, "Setting %s", request_type_to_string(req->type));
|
||||
|
||||
log_link_debug(link, "Setting %s", set_link_operation_to_string(op));
|
||||
|
||||
if (op == SET_LINK_BOND)
|
||||
if (req->type == REQUEST_TYPE_SET_LINK_BOND)
|
||||
r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_NEWLINK, link->master_ifindex);
|
||||
else if (IN_SET(op, SET_LINK_CAN, SET_LINK_IPOIB))
|
||||
else if (IN_SET(req->type, REQUEST_TYPE_SET_LINK_CAN, REQUEST_TYPE_SET_LINK_IPOIB))
|
||||
r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_NEWLINK, link->ifindex);
|
||||
else
|
||||
r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_SETLINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = link_configure_fill_message(link, m, op, req->userdata);
|
||||
r = link_configure_fill_message(link, m, req->type, req->userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -476,7 +453,6 @@ static bool netdev_is_ready(NetDev *netdev) {
|
||||
}
|
||||
|
||||
static int link_is_ready_to_set_link(Link *link, Request *req) {
|
||||
SetLinkOperation op;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -484,26 +460,29 @@ static int link_is_ready_to_set_link(Link *link, Request *req) {
|
||||
assert(link->network);
|
||||
assert(req);
|
||||
|
||||
op = PTR_TO_INT(req->set_link_operation_ptr);
|
||||
|
||||
if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
|
||||
return false;
|
||||
|
||||
switch (op) {
|
||||
case SET_LINK_BOND:
|
||||
case SET_LINK_BRIDGE:
|
||||
switch (req->type) {
|
||||
case REQUEST_TYPE_SET_LINK_BOND:
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE:
|
||||
if (!link->master_set)
|
||||
return false;
|
||||
|
||||
if (link->network->keep_master && link->master_ifindex <= 0)
|
||||
return false;
|
||||
break;
|
||||
case SET_LINK_BRIDGE_VLAN:
|
||||
|
||||
case REQUEST_TYPE_SET_LINK_BRIDGE_VLAN:
|
||||
if (!link->master_set)
|
||||
return false;
|
||||
|
||||
if (link->network->keep_master && link->master_ifindex <= 0 && !streq_ptr(link->kind, "bridge"))
|
||||
return false;
|
||||
|
||||
break;
|
||||
case SET_LINK_CAN:
|
||||
|
||||
case REQUEST_TYPE_SET_LINK_CAN:
|
||||
/* Do not check link->set_flgas_messages here, as it is ok even if link->flags
|
||||
* is outdated, and checking the counter causes a deadlock. */
|
||||
if (FLAGS_SET(link->flags, IFF_UP)) {
|
||||
@ -513,7 +492,8 @@ static int link_is_ready_to_set_link(Link *link, Request *req) {
|
||||
return r;
|
||||
}
|
||||
break;
|
||||
case SET_LINK_MAC:
|
||||
|
||||
case REQUEST_TYPE_SET_LINK_MAC:
|
||||
if (req->netlink_handler == link_set_mac_handler) {
|
||||
/* This is the second attempt to set hardware address. On the first attempt
|
||||
* req->netlink_handler points to link_set_mac_allow_retry_handler().
|
||||
@ -523,12 +503,12 @@ static int link_is_ready_to_set_link(Link *link, Request *req) {
|
||||
return r;
|
||||
}
|
||||
break;
|
||||
case SET_LINK_MASTER: {
|
||||
|
||||
case REQUEST_TYPE_SET_LINK_MASTER: {
|
||||
uint32_t m = 0;
|
||||
Request req_mac = {
|
||||
.link = link,
|
||||
.type = REQUEST_TYPE_SET_LINK,
|
||||
.set_link_operation_ptr = INT_TO_PTR(SET_LINK_MAC),
|
||||
.type = REQUEST_TYPE_SET_LINK_MAC,
|
||||
};
|
||||
|
||||
if (link->network->batadv) {
|
||||
@ -565,11 +545,10 @@ static int link_is_ready_to_set_link(Link *link, Request *req) {
|
||||
req->userdata = UINT32_TO_PTR(m);
|
||||
break;
|
||||
}
|
||||
case SET_LINK_MTU: {
|
||||
case REQUEST_TYPE_SET_LINK_MTU: {
|
||||
Request req_ipoib = {
|
||||
.link = link,
|
||||
.type = REQUEST_TYPE_SET_LINK,
|
||||
.set_link_operation_ptr = INT_TO_PTR(SET_LINK_IPOIB),
|
||||
.type = REQUEST_TYPE_SET_LINK_IPOIB,
|
||||
};
|
||||
|
||||
return !ordered_set_contains(link->manager->request_queue, &req_ipoib);
|
||||
@ -581,19 +560,11 @@ static int link_is_ready_to_set_link(Link *link, Request *req) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int request_process_set_link(Request *req) {
|
||||
SetLinkOperation op;
|
||||
Link *link;
|
||||
int link_process_set_link(Request *req, Link *link, void *userdata) {
|
||||
int r;
|
||||
|
||||
assert(req);
|
||||
assert(req->type == REQUEST_TYPE_SET_LINK);
|
||||
assert(req->netlink_handler);
|
||||
assert_se(link = req->link);
|
||||
|
||||
op = PTR_TO_INT(req->set_link_operation_ptr);
|
||||
|
||||
assert(op >= 0 && op < _SET_LINK_OPERATION_MAX);
|
||||
assert(link);
|
||||
|
||||
r = link_is_ready_to_set_link(link, req);
|
||||
if (r <= 0)
|
||||
@ -601,15 +572,14 @@ int request_process_set_link(Request *req) {
|
||||
|
||||
r = link_configure(link, req);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Failed to set %s: %m",
|
||||
set_link_operation_to_string(op));
|
||||
return log_link_warning_errno(link, r, "Failed to set %s", request_type_to_string(req->type));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int link_request_set_link(
|
||||
Link *link,
|
||||
SetLinkOperation op,
|
||||
RequestType type,
|
||||
request_netlink_handler_t netlink_handler,
|
||||
Request **ret) {
|
||||
|
||||
@ -617,16 +587,15 @@ static int link_request_set_link(
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(op >= 0 && op < _SET_LINK_OPERATION_MAX);
|
||||
assert(netlink_handler);
|
||||
|
||||
r = link_queue_request(link, REQUEST_TYPE_SET_LINK, INT_TO_PTR(op), false,
|
||||
r = link_queue_request(link, type, NULL, false,
|
||||
&link->set_link_messages, netlink_handler, &req);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to request to set %s: %m",
|
||||
set_link_operation_to_string(op));
|
||||
return log_link_warning_errno(link, r, "Failed to request to set %s: %m",
|
||||
request_type_to_string(type));
|
||||
|
||||
log_link_debug(link, "Requested to set %s", set_link_operation_to_string(op));
|
||||
log_link_debug(link, "Requested to set %s", request_type_to_string(type));
|
||||
|
||||
if (ret)
|
||||
*ret = req;
|
||||
@ -662,7 +631,9 @@ int link_request_to_set_addrgen_mode(Link *link) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = link_request_set_link(link, SET_LINK_ADDRESS_GENERATION_MODE, link_set_addrgen_mode_handler, &req);
|
||||
r = link_request_set_link(link, REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE,
|
||||
link_set_addrgen_mode_handler,
|
||||
&req);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -687,7 +658,8 @@ int link_request_to_set_bond(Link *link) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return link_request_set_link(link, SET_LINK_BOND, link_set_bond_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_BOND,
|
||||
link_set_bond_handler, NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_bridge(Link *link) {
|
||||
@ -707,7 +679,9 @@ int link_request_to_set_bridge(Link *link) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return link_request_set_link(link, SET_LINK_BRIDGE, link_set_bridge_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_BRIDGE,
|
||||
link_set_bridge_handler,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_bridge_vlan(Link *link) {
|
||||
@ -730,7 +704,9 @@ int link_request_to_set_bridge_vlan(Link *link) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return link_request_set_link(link, SET_LINK_BRIDGE_VLAN, link_set_bridge_vlan_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_BRIDGE_VLAN,
|
||||
link_set_bridge_vlan_handler,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_can(Link *link) {
|
||||
@ -743,7 +719,9 @@ int link_request_to_set_can(Link *link) {
|
||||
if (!streq_ptr(link->kind, "can"))
|
||||
return 0;
|
||||
|
||||
return link_request_set_link(link, SET_LINK_CAN, link_set_can_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_CAN,
|
||||
link_set_can_handler,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_flags(Link *link) {
|
||||
@ -756,7 +734,9 @@ int link_request_to_set_flags(Link *link) {
|
||||
link->network->promiscuous < 0)
|
||||
return 0;
|
||||
|
||||
return link_request_set_link(link, SET_LINK_FLAGS, link_set_flags_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_FLAGS,
|
||||
link_set_flags_handler,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_group(Link *link) {
|
||||
@ -766,7 +746,9 @@ int link_request_to_set_group(Link *link) {
|
||||
if (link->network->group < 0)
|
||||
return 0;
|
||||
|
||||
return link_request_set_link(link, SET_LINK_GROUP, link_set_group_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_GROUP,
|
||||
link_set_group_handler,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_mac(Link *link, bool allow_retry) {
|
||||
@ -787,7 +769,7 @@ int link_request_to_set_mac(Link *link, bool allow_retry) {
|
||||
if (hw_addr_equal(&link->hw_addr, &link->requested_hw_addr))
|
||||
return 0;
|
||||
|
||||
return link_request_set_link(link, SET_LINK_MAC,
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_MAC,
|
||||
allow_retry ? link_set_mac_allow_retry_handler : link_set_mac_handler,
|
||||
NULL);
|
||||
}
|
||||
@ -803,7 +785,9 @@ int link_request_to_set_ipoib(Link *link) {
|
||||
link->network->ipoib_umcast < 0)
|
||||
return 0;
|
||||
|
||||
return link_request_set_link(link, SET_LINK_IPOIB, link_set_ipoib_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_IPOIB,
|
||||
link_set_ipoib_handler,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_master(Link *link) {
|
||||
@ -818,15 +802,19 @@ int link_request_to_set_master(Link *link) {
|
||||
link->master_set = false;
|
||||
|
||||
if (link->network->batadv || link->network->bond || link->network->bridge || link->network->vrf)
|
||||
return link_request_set_link(link, SET_LINK_MASTER, link_set_master_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_MASTER,
|
||||
link_set_master_handler,
|
||||
NULL);
|
||||
else
|
||||
return link_request_set_link(link, SET_LINK_MASTER, link_unset_master_handler, NULL);
|
||||
return link_request_set_link(link, REQUEST_TYPE_SET_LINK_MASTER,
|
||||
link_unset_master_handler,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int link_request_to_set_mtu(Link *link, uint32_t mtu) {
|
||||
Request *req;
|
||||
const char *origin;
|
||||
uint32_t min_mtu;
|
||||
Request *req;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -862,7 +850,9 @@ int link_request_to_set_mtu(Link *link, uint32_t mtu) {
|
||||
if (link->mtu == mtu)
|
||||
return 0;
|
||||
|
||||
r = link_request_set_link(link, SET_LINK_MTU, link_set_mtu_handler, &req);
|
||||
r = link_request_set_link(link, REQUEST_TYPE_SET_LINK_MTU,
|
||||
link_set_mtu_handler,
|
||||
&req);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -2,30 +2,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct Link Link;
|
||||
typedef struct Request Request;
|
||||
|
||||
typedef enum SetLinkOperation {
|
||||
SET_LINK_ADDRESS_GENERATION_MODE, /* Setting IPv6LL address generation mode. */
|
||||
SET_LINK_BOND, /* Setting bond configs. */
|
||||
SET_LINK_BRIDGE, /* Setting bridge configs. */
|
||||
SET_LINK_BRIDGE_VLAN, /* Setting bridge VLAN configs. */
|
||||
SET_LINK_CAN, /* Setting CAN interface configs. */
|
||||
SET_LINK_FLAGS, /* Setting IFF_NOARP or friends. */
|
||||
SET_LINK_GROUP, /* Setting interface group. */
|
||||
SET_LINK_IPOIB, /* Setting IPoIB configs. */
|
||||
SET_LINK_MAC, /* Setting MAC address. */
|
||||
SET_LINK_MASTER, /* Setting IFLA_MASTER. */
|
||||
SET_LINK_MTU, /* Setting MTU. */
|
||||
_SET_LINK_OPERATION_MAX,
|
||||
_SET_LINK_OPERATION_INVALID = -EINVAL,
|
||||
} SetLinkOperation;
|
||||
|
||||
/* SetLinkOperation is casted to int, then stored in void* with INT_TO_PTR(). */
|
||||
assert_cc(sizeof(SetLinkOperation) <= sizeof(void*));
|
||||
assert_cc(sizeof(SetLinkOperation) <= sizeof(int));
|
||||
|
||||
int link_request_to_set_addrgen_mode(Link *link);
|
||||
int link_request_to_set_bond(Link *link);
|
||||
int link_request_to_set_bridge(Link *link);
|
||||
@ -40,7 +21,7 @@ int link_request_to_set_mtu(Link *link, uint32_t mtu);
|
||||
|
||||
int link_configure_mtu(Link *link);
|
||||
|
||||
int request_process_set_link(Request *req);
|
||||
int link_process_set_link(Request *req, Link *link, void *userdata);
|
||||
|
||||
int link_process_activation(Request *req, Link *link, void *userdata);
|
||||
int link_request_to_activate(Link *link);
|
||||
|
Loading…
Reference in New Issue
Block a user