Revert "Fix dhcpmon"

This reverts commit e30d559c5c.
This commit is contained in:
kellyyeh 2022-04-08 17:00:32 +00:00 committed by Guohan Lu
parent d5cd359eeb
commit 28d4a88b3b
5 changed files with 5 additions and 89 deletions

View File

@ -27,7 +27,7 @@ RUN rm -rf /debs
COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
COPY ["docker-dhcp-relay.supervisord.conf.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
COPY ["dhcp-relay.programs.j2", "dhcpv4-relay.agents.j2", "dhcpv6-relay.agents.j2", "dhcpv6-relay.monitors.j2", "/usr/share/sonic/templates/"]
COPY ["dhcp-relay.programs.j2", "dhcpv4-relay.agents.j2", "dhcpv6-relay.agents.j2", "dhcp-relay.monitors.j2", "/usr/share/sonic/templates/"]
COPY ["critical_processes", "/etc/supervisor"]
ENTRYPOINT ["/usr/bin/docker_init.sh"]

View File

@ -1,73 +0,0 @@
[group:dhcpmon]
programs=
{%- set add_preceding_comma = { 'flag': False } %}
{% set monitor_instance = { 'flag': False } %}
{% for vlan_name in vlan_list %}
{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %}
{% set _dummy = monitor_instance.update({'flag': True}) %}
{%- endif %}
{% if DHCP_RELAY and vlan_name in DHCP_RELAY and 'dhcpv6_servers' in DHCP_RELAY[vlan_name] %}
{% set _dummy = monitor_instance.update({'flag': True}) %}
{% endif %}
{% if monitor_instance.flag %}
{% if add_preceding_comma.flag %},{% endif %}
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
dhcpmon-{{ vlan_name }}
{%- set _dummy = monitor_instance.update({'flag': False}) %}
{%- endif %}
{% endfor %}
{# Create a program entry for each DHCP MONitor instance #}
{% set relay_for_ipv4 = { 'flag': False } %}
{% set relay_for_ipv6 = { 'flag': False } %}
{% for vlan_name in vlan_list %}
{# Check DHCPv4 agents #}
{% if VLAN and vlan_name in VLAN and VLAN[vlan_name]['dhcp_servers'] %}
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{% if dhcp_server | ipv4 %}
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
{% endif %}
{% endfor %}
{% endif %}
{# Check DHCPv6 agents #}
{% if DHCP_RELAY and vlan_name in DHCP_RELAY and 'dhcpv6_servers' in DHCP_RELAY[vlan_name] %}
{% for dhcpv6_server in DHCP_RELAY[vlan_name]['dhcpv6_servers'] %}
{% if dhcpv6_server | ipv6 %}
{% set _dummy = relay_for_ipv6.update({'flag': True}) %}
{% endif %}
{% endfor %}
{% endif %}
{% if relay_for_ipv4.flag or relay_for_ipv6.flag %}
[program:dhcpmon-{{ vlan_name }}]
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
command=/usr/sbin/dhcpmon -id {{ vlan_name }}
{#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #}
{% for (name, prefix) in VLAN_INTERFACE %}
{% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%}
{% endfor %}
{% for (name, prefix) in INTERFACE %}
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
{% endfor %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
{% if prefix | ipv4 %} -iu {{ name }}{% endif -%}
{% endfor %}
{% if MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE %}
{% if prefix | ipv4 %} -im {{ name }}{% endif -%}
{% endfor %}
{% endif %}
{% if relay_for_ipv4.flag %} -4{% endif %}
{% if relay_for_ipv6.flag %} -6{% endif %}
priority=4
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
{% set _dummy = relay_for_ipv6.update({'flag': False}) %}
{% endif %}
{% endfor %}

View File

@ -24,7 +24,6 @@ stderr_logfile=syslog
{# Count how many VLANs require a DHCP relay agent... #}
{% set ipv4_num_relays = { 'count': 0 } %}
{% set ipv6_num_relays = { 'count': 0 } %}
{% set d = namespace(vlan_list=[]) %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% if name not in d.vlan_list %}
{% set d.vlan_list = d.vlan_list + [name] %}
@ -51,6 +50,6 @@ stderr_logfile=syslog
{% include 'dhcpv4-relay.agents.j2' %}
{% include 'dhcpv6-relay.agents.j2' %}
{% include 'dhcpv6-relay.monitors.j2' %}
{% include 'dhcp-relay.monitors.j2' %}
{% endif %}
{% endif %}

View File

@ -18,6 +18,7 @@
#include <arpa/inet.h>
#include <unistd.h>
#include <syslog.h>
#include <libexplain/ioctl.h>
#include <linux/filter.h>
#include <netpacket/packet.h>
#include <sys/types.h>
@ -704,14 +705,14 @@ int initialize_intf_mac_and_ip_addr(dhcp_device_context_t *context)
// Get v4 network address
if (ioctl(fd, SIOCGIFADDR, &ifr) == -1) {
syslog(LOG_ALERT, "ioctl: %s", strerror(errno));
syslog(LOG_ALERT, "ioctl: %s", explain_ioctl(fd, SIOCGIFADDR, &ifr));
break;
}
context->ipv4 = ((struct sockaddr_in*) &ifr.ifr_addr)->sin_addr.s_addr;
// Get mac address
if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
syslog(LOG_ALERT, "ioctl: %s", strerror(errno));
syslog(LOG_ALERT, "ioctl: %s", explain_ioctl(fd, SIOCGIFHWADDR, &ifr));
break;
}
memcpy(context->mac, ifr.ifr_hwaddr.sa_data, sizeof(context->mac));

View File

@ -63,17 +63,6 @@ dhcp_device_context_t* dhcp_devman_get_mgmt_dev();
*/
int dhcp_devman_add_intf(const char *name, char intf_type);
/**
* @code dhcp_devman_setup_dual_tor_mode(name);
*
* @brief set up dual tor mode: 1) set dual_tor_mode flag and 2) retrieve loopback_ip.
*
* @param name interface name
*
* @return 0 on success, nonzero otherwise
*/
int dhcp_devman_setup_dual_tor_mode(const char *name);
/**
* @code dhcp_devman_start_capture(snaplen, base);
*