1+ /* *
2+ * @file dhcp_check_profile.h
3+ *
4+ * For each different dhcp/v6 message, we will have different check profile to validate the packet. We expect different things
5+ * from different topology and message type. Include this header to use the dhcp/v6_msg_check_type_t enum and different profile.
6+ */
7+
8+ #ifndef DHCPV6_CHECK_PROFILE_H_
9+ #define DHCPV6_CHECK_PROFILE_H_
10+
11+ #include < unordered_map>
12+
13+ #include " dhcp_device.h"
14+
15+ /* *
16+ * DHCP msg check type
17+ **/
18+ typedef enum
19+ {
20+ DHCP_CHECK_INTF_TYPE, // check packet interface type (uplink/downlink/mgmt)
21+ DHCP_CHECK_SRC_IP, // check source ip address
22+ DHCP_CHECK_DST_IP, // check destination ip address
23+ DHCP_CHECK_GIADDR, // check giaddr address
24+ DHCP_CHECK_TYPE_COUNT // number of check types
25+ } dhcp_msg_check_type_t ;
26+
27+ /* *
28+ * DHCPv6 msg check type
29+ **/
30+ typedef enum
31+ {
32+ DHCPV6_CHECK_INTF_TYPE, // check packet interface type (uplink/downlink/mgmt)
33+ DHCPV6_CHECK_SRC_IP, // check source ip address
34+ DHCPV6_CHECK_DST_IP, // check destination ip address
35+ DHCPV6_CHECK_LINK_ADDR, // check link address
36+ DHCPV6_CHECK_LINK_ADDR_INNER_MSG_RELAY, // check link address when relay message option is relay (relay option present)
37+ DHCPV6_CHECK_LINK_ADDR_INNER_MSG_NOT_RELAY, // check link address when relay message option is not relay (relay option present)
38+ DHCPV6_CHECK_PEER_ADDR, // check peer address
39+ DHCPV6_CHECK_INTERFACE_ID, // check interface ID, it is by itself optional, by default off for single tor and on for dual tor
40+ DHCPV6_CHECK_HOP_COUNT, // check hop count, we don't need arg for this
41+ DHCPV6_CHECK_HAS_RELAY_OPT, // check has relay message option
42+ DHCPV6_CHECK_TYPE_COUNT // number of check types
43+ } dhcpv6_msg_check_type_t ;
44+
45+ /* *
46+ * DHCP msg check profile type, each entry corresponds to a dhcp_msg_check_type_t and its arg, cast to void pointer for consistency
47+ * this is for a single dhcp message type
48+ */
49+ // This is the preferred style, but compiler isn't supporting it yet
50+ // typedef const void* const dhcp_msg_check_profile_t[DHCP_CHECK_TYPE_COUNT];
51+ // Unfortunately we have to drop the const here because we still want array like access but also want to use unordered_map
52+ // Uninitialized entries will be initialized to NULL when we loop through the all the enum values
53+ typedef std::unordered_map<dhcp_msg_check_type_t , const void *> dhcp_msg_check_profile_t ;
54+
55+ /* *
56+ * DHCPv6 msg check profile type, each entry corresponds to a dhcpv6_msg_check_type_t and its arg, cast to void pointer for consistency
57+ * this is for a single dhcpv6 message type
58+ */
59+ // typedef const void* const dhcpv6_msg_check_profile_t[DHCPV6_CHECK_TYPE_COUNT];
60+ typedef std::unordered_map<dhcpv6_msg_check_type_t , const void *> dhcpv6_msg_check_profile_t ;
61+
62+ /* *
63+ * DHCP check profile type, each entry corresponds to a dhcp message type and its check profile
64+ * this is for all dhcp message types
65+ */
66+ // typedef const dhcp_msg_check_profile_t* const dhcp_check_profile_t[DHCP_MESSAGE_TYPE_COUNT];
67+ typedef std::unordered_map<dhcp_message_type_t , dhcp_msg_check_profile_t *> dhcp_check_profile_t ;
68+
69+ /* *
70+ * DHCPv6 check profile type, each entry corresponds to a dhcpv6 message type and its check profile
71+ * this is for all dhcpv6 message types
72+ */
73+ // typedef const dhcpv6_msg_check_profile_t* const dhcpv6_check_profile_t[DHCPV6_MESSAGE_TYPE_COUNT];
74+ typedef std::unordered_map<dhcpv6_message_type_t , dhcpv6_msg_check_profile_t *> dhcpv6_check_profile_t ;
75+
76+ /* *
77+ * @code get_check_type_desc(c);
78+ * @brief get string description of dhcp_msg_check_type_t
79+ * @param c dhcp_msg_check_type_t
80+ * @return string description
81+ */
82+ inline const char * get_check_type_desc (dhcp_msg_check_type_t c) {
83+ switch (c) {
84+ case DHCP_CHECK_INTF_TYPE: return " DHCP_CHECK_INTF_TYPE" ;
85+ case DHCP_CHECK_SRC_IP: return " DHCP_CHECK_SRC_IP" ;
86+ case DHCP_CHECK_DST_IP: return " DHCP_CHECK_DST_IP" ;
87+ case DHCP_CHECK_GIADDR: return " DHCP_CHECK_GIADDR" ;
88+ case DHCP_CHECK_TYPE_COUNT: return " DHCP_CHECK_TYPE_COUNT" ;
89+ default : return " UNKNOWN DHCP_CHECK_TYPE" ;
90+ }
91+ }
92+
93+ /* *
94+ * @code get_check_type_desc_v6(c);
95+ * @brief get string description of dhcpv6_msg_check_type_t
96+ * @param c dhcpv6_msg_check_type_t
97+ * @return string description
98+ */
99+ inline const char * get_check_type_desc_v6 (dhcpv6_msg_check_type_t c) {
100+ switch (c) {
101+ case DHCPV6_CHECK_INTF_TYPE: return " DHCPV6_CHECK_INTF_TYPE" ;
102+ case DHCPV6_CHECK_SRC_IP: return " DHCPV6_CHECK_SRC_IP" ;
103+ case DHCPV6_CHECK_DST_IP: return " DHCPV6_CHECK_DST_IP" ;
104+ case DHCPV6_CHECK_LINK_ADDR: return " DHCPV6_CHECK_LINK_ADDR" ;
105+ case DHCPV6_CHECK_LINK_ADDR_INNER_MSG_RELAY: return " DHCPV6_CHECK_LINK_ADDR_INNER_MSG_RELAY" ;
106+ case DHCPV6_CHECK_LINK_ADDR_INNER_MSG_NOT_RELAY: return " DHCPV6_CHECK_LINK_ADDR_INNER_MSG_NOT_RELAY" ;
107+ case DHCPV6_CHECK_PEER_ADDR: return " DHCPV6_CHECK_PEER_ADDR" ;
108+ case DHCPV6_CHECK_INTERFACE_ID: return " DHCPV6_CHECK_INTERFACE_ID" ;
109+ case DHCPV6_CHECK_HOP_COUNT: return " DHCPV6_CHECK_HOP_COUNT" ;
110+ case DHCPV6_CHECK_HAS_RELAY_OPT: return " DHCPV6_CHECK_HAS_RELAY_OPT" ;
111+ case DHCPV6_CHECK_TYPE_COUNT: return " DHCPV6_CHECK_TYPE_COUNT" ;
112+ default : return " UNKNOWN DHCPV6_CHECK_TYPE" ;
113+ }
114+ }
115+
116+ // dhcp check profile to use
117+ extern dhcp_check_profile_t * dhcp_check_profile_ptr_rx;
118+ extern dhcp_check_profile_t * dhcp_check_profile_ptr_tx;
119+
120+ // dhcpv6 check profile to use
121+ extern dhcpv6_check_profile_t * dhcpv6_check_profile_ptr_rx;
122+ extern dhcpv6_check_profile_t * dhcpv6_check_profile_ptr_tx;
123+
124+ // dhcp check profile for T0 topology
125+ extern dhcp_check_profile_t dhcp_check_profile_t0_relay_rx;
126+ extern dhcp_check_profile_t dhcp_check_profile_t0_relay_tx;
127+
128+ // dhcpv6 check profile for T0/T1 topology
129+ extern dhcpv6_check_profile_t dhcpv6_check_profile_relay_rx;
130+ extern dhcpv6_check_profile_t dhcpv6_check_profile_relay_tx;
131+
132+ #endif /* DHCPV6_CHECK_PROFILE_H_ */
0 commit comments