2 * Copyright (c) 2016 Red Hat, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 struct dhcp_opts_map {
24 struct hmap_node hmap_node;
30 #define DHCP_OPTION(NAME, CODE, TYPE) \
31 {.name = NAME, .code = CODE, .type = TYPE}
33 #define OFFERIP DHCP_OPTION("offerip", 0, "ipv4")
34 #define DHCP_OPT_NETMASK DHCP_OPTION("netmask", 1, "ipv4")
35 #define DHCP_OPT_ROUTER DHCP_OPTION("router", 3, "ipv4")
36 #define DHCP_OPT_DNS_SERVER DHCP_OPTION("dns_server", 6, "ipv4")
37 #define DHCP_OPT_LOG_SERVER DHCP_OPTION("log_server", 7, "ipv4")
38 #define DHCP_OPT_LPR_SERVER DHCP_OPTION("lpr_server", 9, "ipv4")
39 #define DHCP_OPT_SWAP_SERVER DHCP_OPTION("swap_server", 16, "ipv4")
41 #define DHCP_OPT_POLICY_FILTER \
42 DHCP_OPTION("policy_filter", 21, "ipv4")
44 #define DHCP_OPT_ROUTER_SOLICITATION \
45 DHCP_OPTION("router_solicitation", 32, "ipv4")
47 #define DHCP_OPT_NIS_SERVER DHCP_OPTION("nis_server", 41, "ipv4")
48 #define DHCP_OPT_NTP_SERVER DHCP_OPTION("ntp_server", 42, "ipv4")
49 #define DHCP_OPT_SERVER_ID DHCP_OPTION("server_id", 54, "ipv4")
50 #define DHCP_OPT_TFTP_SERVER DHCP_OPTION("tftp_server", 66, "ipv4")
52 #define DHCP_OPT_CLASSLESS_STATIC_ROUTE \
53 DHCP_OPTION("classless_static_route", 121, "static_routes")
54 #define DHCP_OPT_MS_CLASSLESS_STATIC_ROUTE \
55 DHCP_OPTION("ms_classless_static_route", 249, "static_routes")
57 #define DHCP_OPT_IP_FORWARD_ENABLE DHCP_OPTION("ip_forward_enable", 19, "bool")
58 #define DHCP_OPT_ROUTER_DISCOVERY DHCP_OPTION("router_discovery", 31, "bool")
59 #define DHCP_OPT_ETHERNET_ENCAP DHCP_OPTION("ethernet_encap", 36, "bool")
61 #define DHCP_OPT_DEFAULT_TTL DHCP_OPTION("default_ttl", 23, "uint8")
63 #define DHCP_OPT_TCP_TTL DHCP_OPTION("tcp_ttl", 37, "uint8")
64 #define DHCP_OPT_MTU DHCP_OPTION("mtu", 26, "uint16")
65 #define DHCP_OPT_LEASE_TIME DHCP_OPTION("lease_time", 51, "uint32")
66 #define DHCP_OPT_T1 DHCP_OPTION("T1", 58, "uint32")
67 #define DHCP_OPT_T2 DHCP_OPTION("T2", 59, "uint32")
69 static inline uint32_t
70 dhcp_opt_hash(char *opt_name)
72 return hash_string(opt_name, 0);
75 static inline struct dhcp_opts_map *
76 dhcp_opts_find(const struct hmap *dhcp_opts, char *opt_name)
78 struct dhcp_opts_map *dhcp_opt;
79 HMAP_FOR_EACH_WITH_HASH (dhcp_opt, hmap_node, dhcp_opt_hash(opt_name),
81 if (!strcmp(dhcp_opt->name, opt_name)) {
90 dhcp_opt_add(struct hmap *dhcp_opts, char *opt_name, size_t code, char *type)
92 struct dhcp_opts_map *dhcp_opt = xzalloc(sizeof *dhcp_opt);
93 dhcp_opt->name = xstrdup(opt_name);
94 dhcp_opt->code = code;
95 dhcp_opt->type = xstrdup(type);
96 hmap_insert(dhcp_opts, &dhcp_opt->hmap_node, dhcp_opt_hash(opt_name));
100 dhcp_opts_destroy(struct hmap *dhcp_opts)
102 struct dhcp_opts_map *dhcp_opt;
103 HMAP_FOR_EACH_POP(dhcp_opt, hmap_node, dhcp_opts) {
104 free(dhcp_opt->name);
105 free(dhcp_opt->type);
108 hmap_destroy(dhcp_opts);
111 #endif /* OVN_DHCP_H */