Skip to content

Commit b8a1274

Browse files
committed
Revert "[dhcp_relay] Enhance DHCP monitor application to support DHCPv6 (sonic-net#8060)"
This reverts commit bef5477.
1 parent cff540f commit b8a1274

File tree

7 files changed

+183
-674
lines changed

7 files changed

+183
-674
lines changed

src/dhcpmon/src/dhcp_device.c

+130-434
Large diffs are not rendered by default.

src/dhcpmon/src/dhcp_device.h

+24-88
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,21 @@
1818

1919

2020
/**
21-
* DHCPv4 message types
21+
* DHCP message types
2222
**/
2323
typedef enum
2424
{
25-
DHCPv4_MESSAGE_TYPE_DISCOVER = 1,
26-
DHCPv4_MESSAGE_TYPE_OFFER = 2,
27-
DHCPv4_MESSAGE_TYPE_REQUEST = 3,
28-
DHCPv4_MESSAGE_TYPE_DECLINE = 4,
29-
DHCPv4_MESSAGE_TYPE_ACK = 5,
30-
DHCPv4_MESSAGE_TYPE_NAK = 6,
31-
DHCPv4_MESSAGE_TYPE_RELEASE = 7,
32-
DHCPv4_MESSAGE_TYPE_INFORM = 8,
33-
34-
DHCPv4_MESSAGE_TYPE_COUNT
35-
} dhcpv4_message_type_t;
36-
37-
/**
38-
* DHCPv6 message types
39-
**/
40-
typedef enum
41-
{
42-
DHCPv6_MESSAGE_TYPE_SOLICIT = 1,
43-
DHCPv6_MESSAGE_TYPE_ADVERTISE = 2,
44-
DHCPv6_MESSAGE_TYPE_REQUEST = 3,
45-
DHCPv6_MESSAGE_TYPE_CONFIRM = 4,
46-
DHCPv6_MESSAGE_TYPE_RENEW = 5,
47-
DHCPv6_MESSAGE_TYPE_REBIND = 6,
48-
DHCPv6_MESSAGE_TYPE_REPLY = 7,
49-
DHCPv6_MESSAGE_TYPE_RELEASE = 8,
50-
DHCPv6_MESSAGE_TYPE_DECLINE = 9,
51-
DHCPv6_MESSAGE_TYPE_RECONFIGURE = 10,
52-
DHCPv6_MESSAGE_TYPE_INFORMATION_REQUEST = 11,
53-
DHCPv6_MESSAGE_TYPE_RELAY_FORWARD = 12,
54-
DHCPv6_MESSAGE_TYPE_RELAY_REPLY = 13,
55-
56-
DHCPv6_MESSAGE_TYPE_COUNT
57-
} dhcpv6_message_type_t;
25+
DHCP_MESSAGE_TYPE_DISCOVER = 1,
26+
DHCP_MESSAGE_TYPE_OFFER = 2,
27+
DHCP_MESSAGE_TYPE_REQUEST = 3,
28+
DHCP_MESSAGE_TYPE_DECLINE = 4,
29+
DHCP_MESSAGE_TYPE_ACK = 5,
30+
DHCP_MESSAGE_TYPE_NAK = 6,
31+
DHCP_MESSAGE_TYPE_RELEASE = 7,
32+
DHCP_MESSAGE_TYPE_INFORM = 8,
33+
34+
DHCP_MESSAGE_TYPE_COUNT
35+
} dhcp_message_type_t;
5836

5937
/** packet direction */
6038
typedef enum
@@ -82,42 +60,26 @@ typedef enum
8260
DHCP_MON_STATUS_INDETERMINATE, /** DHCP relay health could not be determined */
8361
} dhcp_mon_status_t;
8462

85-
/** dhcp type */
86-
typedef enum
87-
{
88-
DHCPv4_TYPE,
89-
DHCPv6_TYPE,
90-
} dhcp_type_t;
91-
9263
/** dhcp check type */
9364
typedef enum
9465
{
9566
DHCP_MON_CHECK_NEGATIVE, /** Presence of relayed DHCP packets activity is flagged as unhealthy state */
9667
DHCP_MON_CHECK_POSITIVE, /** Validate that received DORA packets are relayed */
9768
} dhcp_mon_check_t;
9869

99-
typedef struct
100-
{
101-
uint64_t v4counters[DHCP_COUNTERS_COUNT][DHCP_DIR_COUNT][DHCPv4_MESSAGE_TYPE_COUNT];
102-
/** current/snapshot counters of DHCPv4 packets */
103-
uint64_t v6counters[DHCP_COUNTERS_COUNT][DHCP_DIR_COUNT][DHCPv6_MESSAGE_TYPE_COUNT];
104-
/** current/snapshot counters of DHCPv6 packets */
105-
} counters_t;
106-
10770
/** DHCP device (interface) context */
10871
typedef struct
10972
{
11073
int sock; /** Raw socket associated with this device/interface */
111-
in_addr_t ipv4; /** ipv4 network address of this device (interface) */
112-
struct in6_addr ipv6; /** ipv6 network address of this device (interface) */
74+
in_addr_t ip; /** network address of this device (interface) */
11375
uint8_t mac[ETHER_ADDR_LEN]; /** hardware address of this device (interface) */
114-
in_addr_t giaddr_ip; /** Gateway IPv4 address */
115-
struct in6_addr v6_vlan_ip; /** Vlan IPv6 address */
76+
in_addr_t giaddr_ip; /** Gateway IP address */
11677
uint8_t is_uplink; /** north interface? */
11778
char intf[IF_NAMESIZE]; /** device (interface) name */
11879
uint8_t *buffer; /** buffer used to read socket data */
11980
size_t snaplen; /** snap length or buffer size */
120-
counters_t counters; /** counters for DHCPv4/6 packets */
81+
uint64_t counters[DHCP_COUNTERS_COUNT][DHCP_DIR_COUNT][DHCP_MESSAGE_TYPE_COUNT];
82+
/** current/snapshot counters of DHCP packets */
12183
} dhcp_device_context_t;
12284

12385
/**
@@ -132,28 +94,16 @@ typedef struct
13294
int initialize_intf_mac_and_ip_addr(dhcp_device_context_t *context);
13395

13496
/**
135-
* @code dhcp_device_get_ipv4(context, ip);
136-
*
137-
* @brief Accessor method
138-
*
139-
* @param context pointer to device (interface) context
140-
* @param ip(out) pointer to device IPv4
141-
*
142-
* @return 0 on success, otherwise for failure
143-
*/
144-
int dhcp_device_get_ipv4(dhcp_device_context_t *context, in_addr_t *ip);
145-
146-
/**
147-
* @code dhcp_device_get_ipv6(context, ip);
97+
* @code dhcp_device_get_ip(context, ip);
14898
*
14999
* @brief Accessor method
150100
*
151101
* @param context pointer to device (interface) context
152-
* @param ip(out) pointer to device IPv6
102+
* @param ip(out) pointer to device IP
153103
*
154104
* @return 0 on success, otherwise for failure
155105
*/
156-
int dhcp_device_get_ipv6(dhcp_device_context_t *context, struct in6_addr *ip);
106+
int dhcp_device_get_ip(dhcp_device_context_t *context, in_addr_t *ip);
157107

158108
/**
159109
* @code dhcp_device_get_aggregate_context();
@@ -180,23 +130,21 @@ int dhcp_device_init(dhcp_device_context_t **context,
180130
uint8_t is_uplink);
181131

182132
/**
183-
* @code dhcp_device_start_capture(context, snaplen, base, giaddr_ip, v6_vlan_ip);
133+
* @code dhcp_device_start_capture(context, snaplen, base, giaddr_ip);
184134
*
185135
* @brief starts packet capture on this interface
186136
*
187137
* @param context pointer to device (interface) context
188138
* @param snaplen length of packet capture
189139
* @param base pointer to libevent base
190140
* @param giaddr_ip gateway IP address
191-
* @param v6_vlan_ip vlan IPv6 address
192141
*
193142
* @return 0 on success, otherwise for failure
194143
*/
195144
int dhcp_device_start_capture(dhcp_device_context_t *context,
196145
size_t snaplen,
197146
struct event_base *base,
198-
in_addr_t giaddr_ip,
199-
struct in6_addr v6_vlan_ip);
147+
in_addr_t giaddr_ip);
200148

201149
/**
202150
* @code dhcp_device_shutdown(context);
@@ -210,18 +158,17 @@ int dhcp_device_start_capture(dhcp_device_context_t *context,
210158
void dhcp_device_shutdown(dhcp_device_context_t *context);
211159

212160
/**
213-
* @code dhcp_device_get_status(check_type, context, type);
161+
* @code dhcp_device_get_status(check_type, context);
214162
*
215163
* @brief collects DHCP relay status info for a given interface. If context is null, it will report aggregate
216164
* status
217165
*
218166
* @param check_type Type of validation
219167
* @param context Device (interface) context
220-
* @param type DHCP type
221168
*
222169
* @return DHCP_MON_STATUS_HEALTHY, DHCP_MON_STATUS_UNHEALTHY, or DHCP_MON_STATUS_INDETERMINATE
223170
*/
224-
dhcp_mon_status_t dhcp_device_get_status(dhcp_mon_check_t check_type, dhcp_device_context_t *context, dhcp_type_t type);
171+
dhcp_mon_status_t dhcp_device_get_status(dhcp_mon_check_t check_type, dhcp_device_context_t *context);
225172

226173
/**
227174
* @code dhcp_device_update_snapshot(context);
@@ -238,21 +185,10 @@ void dhcp_device_update_snapshot(dhcp_device_context_t *context);
238185
* @brief prints status counters to syslog. If context is null, it will print aggregate status
239186
*
240187
* @param context Device (interface) context
241-
* @param type Counter type to be printed
188+
* @param counters_type Counter type to be printed
242189
*
243190
* @return none
244191
*/
245192
void dhcp_device_print_status(dhcp_device_context_t *context, dhcp_counters_type_t type);
246193

247-
/**
248-
* @code dhcp_device_active_types(dhcpv4, dhcpv6);
249-
*
250-
* @brief update local variables with active protocols
251-
*
252-
* @param dhcpv4 DHCPv4 enable flag
253-
* @param dhcpv6 DHCPv6 enable flag
254-
*
255-
* @return none
256-
*/
257-
void dhcp_device_active_types(bool dhcpv4, bool dhcpv6);
258194
#endif /* DHCP_DEVICE_H_ */

src/dhcpmon/src/dhcp_devman.c

+9-25
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <syslog.h>
1010
#include <sys/queue.h>
1111
#include <stdlib.h>
12-
#include <arpa/inet.h>
13-
#include <stdbool.h>
1412

1513
#include "dhcp_devman.h"
1614

@@ -37,8 +35,7 @@ static uint32_t dhcp_num_mgmt_intf = 0;
3735

3836
/** On Device vlan interface IP address corresponding vlan downlink IP
3937
* This IP is used to filter Offer/Ack packet coming from DHCP server */
40-
static in_addr_t v4_vlan_ip = 0;
41-
static struct in6_addr v6_vlan_ip = {0};
38+
static in_addr_t vlan_ip = 0;
4239

4340
/* Device loopback interface ip, which will be used as the giaddr in dual tor setup. */
4441
static in_addr_t loopback_ip = 0;
@@ -139,8 +136,7 @@ int dhcp_devman_add_intf(const char *name, char intf_type)
139136

140137
rv = dhcp_device_init(&dev->dev_context, dev->name, dev->is_uplink);
141138
if (rv == 0 && intf_type == 'd') {
142-
rv = dhcp_device_get_ipv4(dev->dev_context, &v4_vlan_ip);
143-
rv = dhcp_device_get_ipv6(dev->dev_context, &v6_vlan_ip);
139+
rv = dhcp_device_get_ip(dev->dev_context, &vlan_ip);
144140

145141
dhcp_device_context_t *agg_dev = dhcp_device_get_aggregate_context();
146142

@@ -178,7 +174,7 @@ int dhcp_devman_setup_dual_tor_mode(const char *name)
178174
}
179175

180176
if (initialize_intf_mac_and_ip_addr(&loopback_intf_context) == 0 &&
181-
dhcp_device_get_ipv4(&loopback_intf_context, &loopback_ip) == 0) {
177+
dhcp_device_get_ip(&loopback_intf_context, &loopback_ip) == 0) {
182178
dual_tor_mode = 1;
183179
} else {
184180
syslog(LOG_ALERT, "failed to retrieve ip addr for loopback interface (%s)", name);
@@ -201,13 +197,11 @@ int dhcp_devman_start_capture(size_t snaplen, struct event_base *base)
201197

202198
if ((dhcp_num_south_intf == 1) && (dhcp_num_north_intf >= 1)) {
203199
LIST_FOREACH(int_ptr, &intfs, entry) {
204-
rv = dhcp_device_start_capture(int_ptr->dev_context, snaplen, base, dual_tor_mode ? loopback_ip : v4_vlan_ip, v6_vlan_ip);
200+
rv = dhcp_device_start_capture(int_ptr->dev_context, snaplen, base, dual_tor_mode ? loopback_ip : vlan_ip);
205201
if (rv == 0) {
206-
char ipv6_addr[INET6_ADDRSTRLEN];
207-
inet_ntop(AF_INET6, &int_ptr->dev_context->ipv6, ipv6_addr, sizeof(ipv6_addr));
208202
syslog(LOG_INFO,
209-
"Capturing DHCP packets on interface %s, ipv4: 0x%08x, ipv6: %s, mac [%02x:%02x:%02x:%02x:%02x:%02x] \n",
210-
int_ptr->name, int_ptr->dev_context->ipv4, ipv6_addr, int_ptr->dev_context->mac[0],
203+
"Capturing DHCP packets on interface %s, ip: 0x%08x, mac [%02x:%02x:%02x:%02x:%02x:%02x] \n",
204+
int_ptr->name, int_ptr->dev_context->ip, int_ptr->dev_context->mac[0],
211205
int_ptr->dev_context->mac[1], int_ptr->dev_context->mac[2], int_ptr->dev_context->mac[3],
212206
int_ptr->dev_context->mac[4], int_ptr->dev_context->mac[5]);
213207
}
@@ -225,13 +219,13 @@ int dhcp_devman_start_capture(size_t snaplen, struct event_base *base)
225219
}
226220

227221
/**
228-
* @code dhcp_devman_get_status(check_type, context, type);
222+
* @code dhcp_devman_get_status(check_type, context);
229223
*
230224
* @brief collects DHCP relay status info.
231225
*/
232-
dhcp_mon_status_t dhcp_devman_get_status(dhcp_mon_check_t check_type, dhcp_device_context_t *context, dhcp_type_t type)
226+
dhcp_mon_status_t dhcp_devman_get_status(dhcp_mon_check_t check_type, dhcp_device_context_t *context)
233227
{
234-
return dhcp_device_get_status(check_type, context, type);
228+
return dhcp_device_get_status(check_type, context);
235229
}
236230

237231
/**
@@ -273,13 +267,3 @@ void dhcp_devman_print_status(dhcp_device_context_t *context, dhcp_counters_type
273267
dhcp_device_print_status(context, type);
274268
}
275269
}
276-
277-
/**
278-
* @code dhcp_devman_active_types(dhcpv4, dhcpv6);
279-
*
280-
* @brief update local variables with active protocols
281-
*/
282-
void dhcp_devman_active_types(bool dhcpv4, bool dhcpv6)
283-
{
284-
dhcp_device_active_types(dhcpv4, dhcpv6);
285-
}

src/dhcpmon/src/dhcp_devman.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,16 @@ int dhcp_devman_setup_dual_tor_mode(const char *name);
8787
int dhcp_devman_start_capture(size_t snaplen, struct event_base *base);
8888

8989
/**
90-
* @code dhcp_devman_get_status(check_type, context, type);
90+
* @code dhcp_devman_get_status(check_type, context);
9191
*
9292
* @brief collects DHCP relay status info.
9393
*
9494
* @param check_type Type of validation
9595
* @param context pointer to device (interface) context
96-
* @param type DHCP type
9796
*
9897
* @return DHCP_MON_STATUS_HEALTHY, DHCP_MON_STATUS_UNHEALTHY, or DHCP_MON_STATUS_INDETERMINATE
9998
*/
100-
dhcp_mon_status_t dhcp_devman_get_status(dhcp_mon_check_t check_type, dhcp_device_context_t *context, dhcp_type_t type);
99+
dhcp_mon_status_t dhcp_devman_get_status(dhcp_mon_check_t check_type, dhcp_device_context_t *context);
101100

102101
/**
103102
* @code dhcp_devman_update_snapshot(context);
@@ -120,16 +119,4 @@ void dhcp_devman_update_snapshot(dhcp_device_context_t *context);
120119
*/
121120
void dhcp_devman_print_status(dhcp_device_context_t *context, dhcp_counters_type_t type);
122121

123-
/**
124-
* @code dhcp_devman_active_types(dhcpv4, dhcpv6);
125-
*
126-
* @brief update local variables with active protocols
127-
*
128-
* @param dhcpv4 flag indicating dhcpv4 is enabled
129-
* @param dhcpv6 flag indicating dhcpv6 is enabled
130-
*
131-
* @return none
132-
*/
133-
void dhcp_devman_active_types(bool dhcpv4, bool dhcpv6);
134-
135122
#endif /* DHCP_DEVMAN_H_ */

0 commit comments

Comments
 (0)