Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DHCP relay] Enlarge alias size to be equal to the definition of linu… #10689

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions dockers/docker-dhcp-relay/dhcp-relay.monitors.j2
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
[group:dhcpmon]
programs=
{%- set add_preceding_comma = { 'flag': False } %}
{% set monitor_instance = { 'flag': False } %}
{% for vlan_name in VLAN_INTERFACE %}
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
{% set _dummy = monitor_instance.update({'flag': True}) %}
{%- endif %}
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
{% set _dummy = monitor_instance.update({'flag': True}) %}
{%- endif %}
{% if monitor_instance.flag %}
{% if vlan_name in ipv4_vlan_interfaces or vlan_name in ipv6_vlan_interfaces %}
{% 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 %}

Expand All @@ -23,21 +15,13 @@ dhcpmon-{{ vlan_name }}
{% set relay_for_ipv6 = { 'flag': False } %}
{% for vlan_name in VLAN_INTERFACE %}
{# Check DHCPv4 agents #}
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{% if dhcp_server | ipv4 %}
{% if vlan_name in ipv4_vlan_interfaces %}
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
{% endif %}
{% endfor %}
{% endif %}
{# Check DHCPv6 agents #}
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %}
{% if dhcpv6_server | ipv6 %}
{% if vlan_name in ipv6_vlan_interfaces %}
{% 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 #}
Expand Down
4 changes: 2 additions & 2 deletions dockers/docker-dhcp-relay/dhcp-relay.programs.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ programs=
{%- set add_preceding_comma = { 'flag': False } %}
{% for vlan_name in VLAN_INTERFACE %}
{# Append DHCPv4 agents #}
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
{% if vlan_name in ipv4_vlan_interfaces %}
{% if add_preceding_comma.flag %},{% endif %}
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
isc-dhcpv4-relay-{{ vlan_name }}
{%- endif %}
{# Append DHCPv6 agents #}
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
{% if vlan_name in ipv6_vlan_interfaces %}
{% if add_preceding_comma.flag %},{% endif %}
{% set _dummy = add_preceding_comma.update({'flag': True}) %}
dhcp6relay
Expand Down
10 changes: 1 addition & 9 deletions dockers/docker-dhcp-relay/dhcpv4-relay.agents.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{# Append DHCPv4 agents #}
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
{% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %}
{% if dhcp_server | ipv4 %}
{% set _dummy = relay_for_ipv4.update({'flag': True}) %}
{% endif %}
{% endfor %}
{% if relay_for_ipv4.flag %}
{% set _dummy = relay_for_ipv4.update({'flag': False}) %}
{% if vlan_name in ipv4_vlan_interfaces %}
[program:isc-dhcpv4-relay-{{ vlan_name }}]
{# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #}
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }}
Expand Down Expand Up @@ -37,4 +30,3 @@ dependent_startup=true
dependent_startup_wait_for=start:exited

{% endif %}
{% endif %}
10 changes: 1 addition & 9 deletions dockers/docker-dhcp-relay/dhcpv6-relay.agents.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{# Append DHCPv6 agents #}
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
{% for dhcpv6_server in VLAN[vlan_name]['dhcpv6_servers'] %}
{% if dhcpv6_server | ipv6 %}
{% set _dummy = relay_for_ipv6.update({'flag': True}) %}
{% endif %}
{% endfor %}
{% if relay_for_ipv6.flag %}
{% set _dummy = relay_for_ipv6.update({'flag': False}) %}
{% if vlan_name in ipv6_vlan_interfaces %}
[program:dhcp6relay]
command=/usr/sbin/dhcp6relay

Expand All @@ -19,4 +12,3 @@ dependent_startup=true
dependent_startup_wait_for=start:exited

{% endif %}
{% endif %}
16 changes: 10 additions & 6 deletions dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ dependent_startup_wait_for=rsyslogd:running
{# If our configuration has VLANs... #}
{% if VLAN_INTERFACE %}
{# Count how many VLANs require a DHCP relay agent... #}
{% set ipv4_num_relays = { 'count': 0 } %}
{% set ipv6_num_relays = { 'count': 0 } %}
{% for vlan_name in VLAN_INTERFACE %}
{% set ipv4_vlan_interfaces = [] %}
{% set ipv6_vlan_interfaces = [] %}
{% for (vlan_name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and vlan_name not in ipv4_vlan_interfaces %}
{% if VLAN and vlan_name in VLAN and 'dhcp_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcp_servers']|length > 0 %}
{% set _dummy = ipv4_num_relays.update({'count': ipv4_num_relays.count + 1}) %}
{% set ipv4_vlan_interfaces = ipv4_vlan_interfaces.append(vlan_name) %}
{% endif %}
{% endif %}
{% if prefix | ipv6 and vlan_name not in ipv6_vlan_interfaces %}
{% if VLAN and vlan_name in VLAN and 'dhcpv6_servers' in VLAN[vlan_name] and VLAN[vlan_name]['dhcpv6_servers']|length > 0 %}
{% set _dummy = ipv6_num_relays.update({'count': ipv6_num_relays.count + 1}) %}
{% set ipv6_vlan_interfaces = ipv6_vlan_interfaces.append(vlan_name) %}
{% endif %}
{% endif %}
{% endfor %}
{# If one or more of the VLANs require a DHCP relay agent... #}
{% if ipv4_num_relays.count > 0 or ipv6_num_relays.count > 0 %}
{% if ipv4_vlan_interfaces|length > 0 or ipv6_vlan_interfaces|length > 0 %}
{% include 'dhcp-relay.programs.j2' %}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
From dfd3ddee21e881863ef4f54d22ec87a86f18acf9 Mon Sep 17 00:00:00 2001
From: irene_pan <irene_pan@edge-core.com>
Date: Tue, 26 Apr 2022 08:13:15 +0000
Subject: [PATCH] [DHCP relay] Enlarge alias size to be equal to the definition
of linux source

---
relay/dhcrelay.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index 7492797..6e67018 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -139,9 +139,16 @@ static void setup_streams(void);
char *dhcrelay_sub_id = NULL;
#endif

+/* * The IFALIASZ value 256 is referred from the linux/if.h
+ * https://github.com/torvalds/linux/blob/master/include/uapi/linux/if.h#L35
+ */
+#ifndef IFALIASZ
+#define IFALIASZ 256
+#endif
+
struct interface_name_alias_tuple {
char if_name[IFNAMSIZ];
- char if_alias[IFNAMSIZ];
+ char if_alias[IFALIASZ];
};

static struct interface_name_alias_tuple *g_interface_name_alias_map = NULL;
@@ -1398,6 +1405,7 @@ format_relay_agent_rfc3046_msg(const struct interface_info *ip, struct dhcp_pack
size_t len = 0;
char hostname[HOST_NAME_MAX] = { 0 };
char ifname[IFNAMSIZ] = { 0 };
+ char ifalias[IFALIASZ] = { 0 };
char *buf = msg;

for ( ; format && *format && len < msgn; ++format) {
@@ -1427,7 +1435,7 @@ format_relay_agent_rfc3046_msg(const struct interface_info *ip, struct dhcp_pack
*/
if (packet->htype && !packet->giaddr.s_addr) {
int ret = 0, vlanid = 0;
- char ifalias[IFNAMSIZ] = { 0 };
+ memset(ifalias, 0, IFALIASZ);

ret = _bridgefdbquery(print_hw_addr(packet->htype, packet->hlen, packet->chaddr),
ifname,
@@ -1448,15 +1456,15 @@ format_relay_agent_rfc3046_msg(const struct interface_info *ip, struct dhcp_pack
ret = get_interface_alias_by_name(ifname, ifalias);
if (ret < 0) {
//log_debug("Failed to retrieve alias for interface name '%s'. Defaulting to interface name.", ifname);
+ str = ifname;
}
else {
//log_debug("Mapped interface name '%s' to alias '%s'. Adding as option 82 interface alias for MAC Address %s",
// ifname, ifalias, print_hw_addr (packet->htype, packet->hlen, packet->chaddr));

- strncpy(ifname, ifalias, IFNAMSIZ);
+ str = ifalias;
}

- str = ifname;
}
break;

@@ -2548,7 +2556,7 @@ get_interface_alias_by_name(const char *if_name, char *if_alias_out) {

for (i = 0; i < g_interface_name_alias_map_size; i++) {
if (strncmp(if_name, g_interface_name_alias_map[i].if_name, IFNAMSIZ) == 0) {
- strncpy(if_alias_out, g_interface_name_alias_map[i].if_alias, IFNAMSIZ);
+ strncpy(if_alias_out, g_interface_name_alias_map[i].if_alias, IFALIASZ);
return 0;
}
}
--
2.35.1

1 change: 1 addition & 0 deletions src/isc-dhcp/patch/series
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
0010-Bugfix-correctly-set-interface-netmask.patch
0011-dhcp-relay-Prevent-Buffer-Overrun.patch
0012-add-option-si-to-support-using-src-intf-ip-in-relay.patch
0013-Enlarge-alias-size-to-be-equal-to-the-def-of-linux.patch
11 changes: 8 additions & 3 deletions src/sonic-config-engine/tests/sample_output/py2/bgpd_frr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.200.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.0.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 15 permit 192.168.200.0/27
!
ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 5 permit fc02::/126
!
!
!
router bgp 65100
Expand All @@ -60,8 +62,11 @@ router bgp 65100
network fc00:1::32/64
exit-address-family
!
network 192.168.200.1/27
address-family ipv6
network FC02::1/126
exit-address-family
network 192.168.0.1/27
network 192.168.200.1/27
!
!
!
Expand Down
11 changes: 8 additions & 3 deletions src/sonic-config-engine/tests/sample_output/py2/frr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.200.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.0.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 15 permit 192.168.200.0/27
!
ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 5 permit fc02::/126
!
!
!
router bgp 65100
Expand All @@ -79,8 +81,11 @@ router bgp 65100
network fc00:1::32/64
exit-address-family
!
network 192.168.200.1/27
address-family ipv6
network FC02::1/126
exit-address-family
network 192.168.0.1/27
network 192.168.200.1/27
!
!
!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"TUNNEL_DECAP_TABLE:IPINIP_V6_TUNNEL" : {
"tunnel_type":"IPINIP",
"dst_ip":"fc00:1::32,fc00::71,fc00::75,fc00::79,fc00::7d",
"dst_ip":"fc00:1::32,fc00::71,fc00::75,fc00::79,fc00::7d,fc02::1",
"dscp_mode":"uniform",
"ecn_mode":"copy_from_outer",
"ttl_mode":"pipe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function wait_until_iface_ready


# Wait for all interfaces with IPv4 addresses to be up and ready
wait_until_iface_ready Vlan2000 192.168.200.1/27
wait_until_iface_ready Vlan1000 192.168.0.1/27
wait_until_iface_ready Vlan2000 192.168.200.1/27
wait_until_iface_ready PortChannel02 10.0.0.58/31
wait_until_iface_ready PortChannel03 10.0.0.60/31
wait_until_iface_ready PortChannel04 10.0.0.62/31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.200.0/27
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 15 permit 192.168.200.0/27
!
ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc02::/126
!
!
!
Expand All @@ -61,6 +63,9 @@ router bgp 65100
exit-address-family
!
network 192.168.0.1/27
address-family ipv6
network FC02::1/126
exit-address-family
network 192.168.200.1/27
!
!
Expand Down
7 changes: 6 additions & 1 deletion src/sonic-config-engine/tests/sample_output/py3/frr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.200.0/27
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 15 permit 192.168.200.0/27
!
ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc02::/126
!
!
!
Expand All @@ -80,6 +82,9 @@ router bgp 65100
exit-address-family
!
network 192.168.0.1/27
address-family ipv6
network FC02::1/126
exit-address-family
network 192.168.200.1/27
!
!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"TUNNEL_DECAP_TABLE:IPINIP_V6_TUNNEL" : {
"tunnel_type":"IPINIP",
"dst_ip":"fc00:1::32,fc00::71,fc00::75,fc00::79,fc00::7d",
"dst_ip":"fc00:1::32,fc00::71,fc00::75,fc00::79,fc00::7d,fc02::1",
"dscp_mode":"uniform",
"ecn_mode":"copy_from_outer",
"ttl_mode":"pipe"
Expand Down
5 changes: 5 additions & 0 deletions src/sonic-config-engine/tests/t0-sample-graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@
<AttachTo>Vlan1000</AttachTo>
<Prefix>192.168.0.1/27</Prefix>
</IPInterface>
<IPInterface>
<Name i:Name="true"/>
<AttachTo>Vlan1000</AttachTo>
<Prefix>FC02::1/126</Prefix>
</IPInterface>
<IPInterface>
<Name i:nil="true"/>
<AttachTo>Vlan2000</AttachTo>
Expand Down