diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-dhcp-server.c | 194 | ||||
-rw-r--r-- | src/network/networkd-dhcp-server.h | 16 | ||||
-rw-r--r-- | src/network/networkd-network-gperf.gperf | 1 | ||||
-rw-r--r-- | src/network/networkd-network.c | 12 | ||||
-rw-r--r-- | src/network/networkd-network.h | 2 |
5 files changed, 218 insertions, 7 deletions
diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c index efb82d7e9a..77eb46341c 100644 --- a/src/network/networkd-dhcp-server.c +++ b/src/network/networkd-dhcp-server.c @@ -2,11 +2,15 @@ #include "sd-dhcp-server.h" +#include "escape.h" #include "networkd-dhcp-server.h" #include "networkd-link.h" #include "networkd-manager.h" #include "networkd-network.h" +#include "parse-util.h" #include "strv.h" +#include "string-table.h" +#include "string-util.h" static Address* link_find_dhcp_server_address(Link *link) { Address *address; @@ -187,9 +191,11 @@ static int link_push_uplink_sip_to_dhcp_server(Link *link, sd_dhcp_server *s) { } int dhcp4_server_configure(Link *link) { - Address *address; - Link *uplink = NULL; bool acquired_uplink = false; + sd_dhcp_raw_option *p; + Link *uplink = NULL; + Address *address; + Iterator i; int r; address = link_find_dhcp_server_address(link); @@ -298,6 +304,15 @@ int dhcp4_server_configure(Link *link) { if (r < 0) return r; } + + ORDERED_HASHMAP_FOREACH(p, link->network->dhcp_server_raw_options, i) { + r = sd_dhcp_server_add_raw_option(link->dhcp_server, p); + if (r == -EEXIST) + continue; + if (r < 0) + return r; + } + if (!sd_dhcp_server_is_running(link->dhcp_server)) { r = sd_dhcp_server_start(link->dhcp_server); if (r < 0) @@ -464,3 +479,178 @@ int config_parse_dhcp_server_sip( n->dhcp_server_sip = m; } } + +static const char * const dhcp_raw_option_data_type_table[_DHCP_RAW_OPTION_DATA_MAX] = { + [DHCP_RAW_OPTION_DATA_UINT8] = "uint8", + [DHCP_RAW_OPTION_DATA_UINT16] = "uint16", + [DHCP_RAW_OPTION_DATA_UINT32] = "uint32", + [DHCP_RAW_OPTION_DATA_STRING] = "string", + [DHCP_RAW_OPTION_DATA_IPV4ADDRESS] = "ipv4address", +}; + +DEFINE_STRING_TABLE_LOOKUP(dhcp_raw_option_data_type, DHCPRawOption); + +int config_parse_dhcp_server_raw_option_data( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + _cleanup_(sd_dhcp_raw_option_unrefp) sd_dhcp_raw_option *opt = NULL, *old = NULL; + _cleanup_free_ char *word = NULL, *q = NULL; + union in_addr_union addr; + Network *network = data; + uint16_t uint16_data; + uint32_t uint32_data; + uint8_t uint8_data; + DHCPRawOption type; + const char *p; + void *udata; + ssize_t sz; + uint8_t u; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if (isempty(rvalue)) { + network->dhcp_server_raw_options = ordered_hashmap_free(network->dhcp_server_raw_options); + return 0; + } + + p = rvalue; + r = extract_first_word(&p, &word, ":", 0); + if (r == -ENOMEM) + return log_oom(); + if (r <= 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Invalid DHCP server send raw option, ignoring assignment: %s", rvalue); + return 0; + } + + r = safe_atou8(word, &u); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse DHCP server send raw option type, ignoring assignment: %s", rvalue); + return 0; + } + if (u < 1 || u >= 255) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Invalid DHCP server send raw option, valid range is 1-254, ignoring assignment: %s", rvalue); + return 0; + } + + free(word); + + r = extract_first_word(&p, &word, ":", 0); + if (r == -ENOMEM) + return log_oom(); + if (r <= 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Invalid DHCP server send raw option, ignoring assignment: %s", rvalue); + return 0; + } + + r = dhcp_raw_option_data_type_from_string(word); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Invalid DHCP server send data type, ignoring assignment: %s", p); + return 0; + } + + type = r; + switch(type) { + case DHCP_RAW_OPTION_DATA_UINT8:{ + r = safe_atou8(p, &uint8_data); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse DHCPv4 vendor specific uint8 data, ignoring assignment: %s", p); + return 0; + } + + udata = &uint8_data; + sz = sizeof(uint8_t); + break; + } + case DHCP_RAW_OPTION_DATA_UINT16:{ + r = safe_atou16(p, &uint16_data); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse DHCPv4 vendor specific uint16 data, ignoring assignment: %s", p); + return 0; + } + + udata = &uint16_data; + sz = sizeof(uint16_t); + break; + } + case DHCP_RAW_OPTION_DATA_UINT32: { + r = safe_atou32(p, &uint32_data); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse DHCPv4 vendor specific uint32 data, ignoring assignment: %s", p); + return 0; + } + + udata = &uint32_data; + sz = sizeof(uint32_t); + + break; + } + case DHCP_RAW_OPTION_DATA_IPV4ADDRESS: { + r = in_addr_from_string(AF_INET, p, &addr); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse DHCPv4 vendor specific ipv4address data, ignoring assignment: %s", p); + return 0; + } + + udata = &addr.in; + sz = sizeof(addr.in.s_addr); + break; + } + case DHCP_RAW_OPTION_DATA_STRING: + sz = cunescape(p, 0, &q); + if (sz < 0) { + log_syntax(unit, LOG_ERR, filename, line, sz, + "Failed to decode option data, ignoring assignment: %s", p); + } + + udata = q; + break; + default: + return -EINVAL; + } + + r = sd_dhcp_raw_option_new(u, udata, sz, &opt); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to store DHCP send raw option '%s', ignoring assignment: %m", rvalue); + return 0; + } + + r = ordered_hashmap_ensure_allocated(&network->dhcp_server_raw_options, &dhcp_raw_options_hash_ops); + if (r < 0) + return log_oom(); + + /* Overwrite existing option */ + old = ordered_hashmap_remove(network->dhcp_server_raw_options, UINT_TO_PTR(u)); + r = ordered_hashmap_put(network->dhcp_server_raw_options, UINT_TO_PTR(u), opt); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to store DHCP server send raw option '%s'", rvalue); + return 0; + } + + TAKE_PTR(opt); + + return 0; +} diff --git a/src/network/networkd-dhcp-server.h b/src/network/networkd-dhcp-server.h index 7c12538096..c30162dd5b 100644 --- a/src/network/networkd-dhcp-server.h +++ b/src/network/networkd-dhcp-server.h @@ -2,11 +2,27 @@ #pragma once #include "conf-parser.h" +#include "networkd-link.h" +#include "networkd-util.h" typedef struct Link Link; +typedef enum DHCPRawOption { + DHCP_RAW_OPTION_DATA_UINT8, + DHCP_RAW_OPTION_DATA_UINT16, + DHCP_RAW_OPTION_DATA_UINT32, + DHCP_RAW_OPTION_DATA_STRING, + DHCP_RAW_OPTION_DATA_IPV4ADDRESS, + _DHCP_RAW_OPTION_DATA_MAX, + _DHCP_RAW_OPTION_DATA_INVALID, +} DHCPRawOption; + +const char *dhcp_raw_option_data_type_to_string(DHCPRawOption d) _const_; +DHCPRawOption dhcp_raw_option_data_type_from_string(const char *d) _pure_; + int dhcp4_server_configure(Link *link); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_sip); +CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_raw_option_data); diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 446ba9f084..9f53385602 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -200,6 +200,7 @@ DHCPServer.EmitTimezone, config_parse_bool, DHCPServer.Timezone, config_parse_timezone, 0, offsetof(Network, dhcp_server_timezone) DHCPServer.PoolOffset, config_parse_uint32, 0, offsetof(Network, dhcp_server_pool_offset) DHCPServer.PoolSize, config_parse_uint32, 0, offsetof(Network, dhcp_server_pool_size) +DHCPServer.SendRawOption, config_parse_dhcp_server_raw_option_data, 0, 0 Bridge.Cost, config_parse_uint32, 0, offsetof(Network, cost) Bridge.UseBPDU, config_parse_tristate, 0, offsetof(Network, use_bpdu) Bridge.HairPin, config_parse_tristate, 0, offsetof(Network, hairpin) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 0956d2a9b7..90d86f35a9 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -11,6 +11,7 @@ #include "fd-util.h" #include "hostname-util.h" #include "in-addr-util.h" +#include "networkd-dhcp-server.h" #include "network-internal.h" #include "networkd-manager.h" #include "networkd-network.h" @@ -144,14 +145,14 @@ static int network_resolve_stacked_netdevs(Network *network) { } int network_verify(Network *network) { - Address *address, *address_next; - Route *route, *route_next; - FdbEntry *fdb, *fdb_next; + RoutingPolicyRule *rule, *rule_next; Neighbor *neighbor, *neighbor_next; AddressLabel *label, *label_next; - Prefix *prefix, *prefix_next; - RoutingPolicyRule *rule, *rule_next; NextHop *nexthop, *nextnop_next; + Address *address, *address_next; + Prefix *prefix, *prefix_next; + Route *route, *route_next; + FdbEntry *fdb, *fdb_next; assert(network); assert(network->filename); @@ -680,6 +681,7 @@ static Network *network_free(Network *network) { set_free_free(network->dnssec_negative_trust_anchors); ordered_hashmap_free(network->dhcp_send_options); + ordered_hashmap_free(network->dhcp_server_raw_options); return mfree(network); } diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 0d4559774c..9258bf55f7 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -16,6 +16,7 @@ #include "networkd-brvlan.h" #include "networkd-dhcp-common.h" #include "networkd-dhcp4.h" +#include "networkd-dhcp-server.h" #include "networkd-fdb.h" #include "networkd-ipv6-proxy-ndp.h" #include "networkd-lldp-rx.h" @@ -114,6 +115,7 @@ struct Network { Set *dhcp_black_listed_ip; Set *dhcp_request_options; OrderedHashmap *dhcp_send_options; + OrderedHashmap *dhcp_server_raw_options; /* DHCPv6 Client support*/ bool dhcp6_use_dns; |