LCOV - code coverage report
Current view: top level - ovn/lib - ovn-dhcp.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 21 21 100.0 %
Date: 2016-09-14 01:02:56 Functions: 4 4 100.0 %
Branches: 9 12 75.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2016 Red Hat, Inc.
       3                 :            :  *
       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:
       7                 :            :  *
       8                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :            :  *
      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.
      15                 :            :  */
      16                 :            : 
      17                 :            : #ifndef OVN_DHCP_H
      18                 :            : #define OVN_DHCP_H 1
      19                 :            : 
      20                 :            : #include "openvswitch/hmap.h"
      21                 :            : #include "hash.h"
      22                 :            : 
      23                 :            : struct dhcp_opts_map {
      24                 :            :     struct hmap_node hmap_node;
      25                 :            :     char *name;
      26                 :            :     char *type;
      27                 :            :     size_t code;
      28                 :            : };
      29                 :            : 
      30                 :            : #define DHCP_OPTION(NAME, CODE, TYPE) \
      31                 :            :     {.name = NAME, .code = CODE, .type = TYPE}
      32                 :            : 
      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")
      40                 :            : 
      41                 :            : #define DHCP_OPT_POLICY_FILTER \
      42                 :            :     DHCP_OPTION("policy_filter", 21, "ipv4")
      43                 :            : 
      44                 :            : #define DHCP_OPT_ROUTER_SOLICITATION \
      45                 :            :     DHCP_OPTION("router_solicitation", 32, "ipv4")
      46                 :            : 
      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")
      51                 :            : 
      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")
      56                 :            : 
      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")
      60                 :            : 
      61                 :            : #define DHCP_OPT_DEFAULT_TTL DHCP_OPTION("default_ttl", 23, "uint8")
      62                 :            : 
      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")
      68                 :            : 
      69                 :            : static inline uint32_t
      70                 :     222487 : dhcp_opt_hash(char *opt_name)
      71                 :            : {
      72                 :     222487 :     return hash_string(opt_name, 0);
      73                 :            : }
      74                 :            : 
      75                 :            : static inline struct dhcp_opts_map *
      76                 :      68685 : dhcp_opts_find(const struct hmap *dhcp_opts, char *opt_name)
      77                 :            : {
      78                 :            :     struct dhcp_opts_map *dhcp_opt;
      79 [ +  + ][ -  + ]:      68685 :     HMAP_FOR_EACH_WITH_HASH (dhcp_opt, hmap_node, dhcp_opt_hash(opt_name),
      80                 :            :                              dhcp_opts) {
      81         [ +  - ]:      68681 :         if (!strcmp(dhcp_opt->name, opt_name)) {
      82                 :      68681 :             return dhcp_opt;
      83                 :            :         }
      84                 :            :     }
      85                 :            : 
      86                 :          4 :     return NULL;
      87                 :            : }
      88                 :            : 
      89                 :            : static inline void
      90                 :      84614 : dhcp_opt_add(struct hmap *dhcp_opts, char *opt_name, size_t code, char *type)
      91                 :            : {
      92                 :      84614 :     struct dhcp_opts_map *dhcp_opt = xzalloc(sizeof *dhcp_opt);
      93                 :      84614 :     dhcp_opt->name = xstrdup(opt_name);
      94                 :      84614 :     dhcp_opt->code = code;
      95                 :      84614 :     dhcp_opt->type = xstrdup(type);
      96                 :      84614 :     hmap_insert(dhcp_opts, &dhcp_opt->hmap_node, dhcp_opt_hash(opt_name));
      97                 :      84614 : }
      98                 :            : 
      99                 :            : static inline void
     100                 :       6336 : dhcp_opts_destroy(struct hmap *dhcp_opts)
     101                 :            : {
     102                 :            :     struct dhcp_opts_map *dhcp_opt;
     103 [ +  + ][ -  + ]:      90950 :     HMAP_FOR_EACH_POP(dhcp_opt, hmap_node, dhcp_opts) {
                 [ +  + ]
     104                 :      84614 :         free(dhcp_opt->name);
     105                 :      84614 :         free(dhcp_opt->type);
     106                 :      84614 :         free(dhcp_opt);
     107                 :            :     }
     108                 :       6336 :     hmap_destroy(dhcp_opts);
     109                 :       6336 : }
     110                 :            : 
     111                 :            : struct dhcp_opt6_header {
     112                 :            :     uint16_t code;
     113                 :            :     uint16_t len;
     114                 :            : };
     115                 :            : 
     116                 :            : /* Supported DHCPv6 Message Types */
     117                 :            : #define DHCPV6_MSG_TYPE_SOLICIT     1
     118                 :            : #define DHCPV6_MSG_TYPE_ADVT        2
     119                 :            : #define DHCPV6_MSG_TYPE_REQUEST     3
     120                 :            : #define DHCPV6_MSG_TYPE_CONFIRM     4
     121                 :            : #define DHCPV6_MSG_TYPE_REPLY       7
     122                 :            : #define DHCPV6_MSG_TYPE_DECLINE     9
     123                 :            : 
     124                 :            : 
     125                 :            : /* DHCPv6 Option codes */
     126                 :            : #define DHCPV6_OPT_CLIENT_ID_CODE        1
     127                 :            : #define DHCPV6_OPT_SERVER_ID_CODE        2
     128                 :            : #define DHCPV6_OPT_IA_NA_CODE            3
     129                 :            : #define DHCPV6_OPT_IA_ADDR_CODE          5
     130                 :            : #define DHCPV6_OPT_DNS_SERVER_CODE       23
     131                 :            : #define DHCPV6_OPT_DOMAIN_SEARCH_CODE    24
     132                 :            : 
     133                 :            : #define DHCPV6_OPT_SERVER_ID \
     134                 :            :     DHCP_OPTION("server_id", DHCPV6_OPT_SERVER_ID_CODE, "mac")
     135                 :            : 
     136                 :            : #define DHCPV6_OPT_IA_ADDR  \
     137                 :            :     DHCP_OPTION("ia_addr", DHCPV6_OPT_IA_ADDR_CODE, "ipv6")
     138                 :            : 
     139                 :            : #define DHCPV6_OPT_DNS_SERVER  \
     140                 :            :     DHCP_OPTION("dns_server", DHCPV6_OPT_DNS_SERVER_CODE, "ipv6")
     141                 :            : 
     142                 :            : #define DHCPV6_OPT_DOMAIN_SEARCH \
     143                 :            :     DHCP_OPTION("domain_search", DHCPV6_OPT_DOMAIN_SEARCH_CODE, "str")
     144                 :            : 
     145                 :            : OVS_PACKED(
     146                 :            : struct dhcpv6_opt_header {
     147                 :            :     ovs_be16 code;
     148                 :            :     ovs_be16 len;
     149                 :            : });
     150                 :            : 
     151                 :            : OVS_PACKED(
     152                 :            : struct dhcpv6_opt_server_id {
     153                 :            :     struct dhcpv6_opt_header opt;
     154                 :            :     ovs_be16 duid_type;
     155                 :            :     ovs_be16 hw_type;
     156                 :            :     struct eth_addr mac;
     157                 :            : });
     158                 :            : 
     159                 :            : 
     160                 :            : OVS_PACKED(
     161                 :            : struct dhcpv6_opt_ia_addr {
     162                 :            :     struct dhcpv6_opt_header opt;
     163                 :            :     struct in6_addr ipv6;
     164                 :            :     ovs_be32 t1;
     165                 :            :     ovs_be32 t2;
     166                 :            : });
     167                 :            : 
     168                 :            : OVS_PACKED(
     169                 :            : struct dhcpv6_opt_ia_na {
     170                 :            :     struct dhcpv6_opt_header opt;
     171                 :            :     ovs_be32 iaid;
     172                 :            :     ovs_be32 t1;
     173                 :            :     ovs_be32 t2;
     174                 :            : });
     175                 :            : 
     176                 :            : #define DHCPV6_DUID_LL      3
     177                 :            : #define DHCPV6_HW_TYPE_ETH  1
     178                 :            : 
     179                 :            : #define DHCPV6_OPT_PAYLOAD(opt) \
     180                 :            :     (void *)((char *)opt + sizeof(struct dhcpv6_opt_header))
     181                 :            : 
     182                 :            : #endif /* OVN_DHCP_H */

Generated by: LCOV version 1.12