Skip to content

Commit ab366fb

Browse files
committed
Incorporate review comments
Signed-off-by: Guvenc Gulce <guevenc.guelce@sap.com>
1 parent 897aaad commit ab366fb

File tree

8 files changed

+18
-22
lines changed

8 files changed

+18
-22
lines changed

include/dp_port.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct dp_port_iface {
4848
bool arp_done;
4949
uint64_t total_flow_rate_cap;
5050
uint64_t public_flow_rate_cap;
51+
uint32_t hostname_len;
5152
};
5253

5354
struct dp_port_async_template {

include/nodes/dhcp_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern "C" {
2121
#define DHCP_OPT_SUBNET_MASK 1
2222
#define DHCP_OPT_ROUTER 3
2323
#define DHCP_OPT_DNS 6
24+
#define DHCP_OPT_HOSTNAME 12
2425
#define DHCP_OPT_INTERFACE_MTU 26
2526
#define DHCP_OPT_IP_LEASE_TIME 51
2627
#define DHCP_OPT_MESSAGE_TYPE 53

src/grpc/dp_grpc_impl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,8 @@ static int dp_process_create_interface(struct dp_grpc_responder *responder)
461461
static_assert(sizeof(request->pxe_str) == sizeof(port->iface.cfg.pxe_str), "Incompatible interface PXE size");
462462
rte_memcpy(port->iface.cfg.pxe_str, request->pxe_str, sizeof(port->iface.cfg.pxe_str));
463463
dp_copy_ipaddr(&port->iface.cfg.pxe_ip, &request->pxe_addr);
464-
// Ensure null termination even if source is exactly max length
465-
rte_memcpy(port->iface.cfg.hostname, request->hostname, sizeof(port->iface.cfg.hostname) - 1);
466-
port->iface.cfg.hostname[sizeof(port->iface.cfg.hostname) - 1] = '\0';
464+
rte_memcpy(port->iface.cfg.hostname, request->hostname, sizeof(port->iface.cfg.hostname));
465+
port->iface.hostname_len = (uint32_t)strnlen(port->iface.cfg.hostname, DP_IFACE_HOSTNAME_MAX_LEN - 1);
467466

468467
/* Do not install routes for an empty(zero) IP, as zero ip is just a marker for showing the disabled IPv4/IPv6 machinery */
469468
if (request->ip4_addr != 0) {

src/nodes/dhcp_node.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ static uint8_t classless_route[sizeof(classless_route_prefix) + sizeof(server_ip
4949
static_assert(DP_VIRTSVC_MAX <= UINT8_MAX+1, "Number of virtual services can be higher than supported link-local subnet size");
5050
#endif
5151

52-
#define DHCP_OPT_HOSTNAME 12
53-
5452
static int dhcp_node_init(__rte_unused const struct rte_graph *graph, __rte_unused struct rte_node *node)
5553
{
5654
server_ip = htonl(dp_get_gw_ip4());
@@ -89,11 +87,10 @@ static __rte_always_inline int add_dhcp_option(uint8_t **pos_ptr, uint8_t *end,
8987
static __rte_always_inline int add_dhcp_options(struct dp_dhcp_header *dhcp_hdr,
9088
uint8_t msg_type,
9189
enum dp_pxe_mode pxe_mode,
92-
const char *hostname)
90+
const struct dp_port *port)
9391
{
9492
uint8_t *pos = dhcp_hdr->options;
9593
uint8_t *end = pos + DHCP_MAX_OPTIONS_LEN;
96-
uint8_t hostname_len;
9794
const struct dp_conf_dhcp_dns *dhcp_dns = dp_conf_get_dhcp_dns();
9895

9996
if (DP_FAILED(add_dhcp_option(&pos, end, DHCP_OPT_MESSAGE_TYPE, &msg_type, sizeof(msg_type)))
@@ -113,12 +110,9 @@ static __rte_always_inline int add_dhcp_options(struct dp_dhcp_header *dhcp_hdr,
113110
if (DP_FAILED(add_dhcp_option(&pos, end, DHCP_OPT_DNS, dhcp_dns->array, dhcp_dns->len)))
114111
return DP_ERROR;
115112

116-
if (hostname && hostname[0] != '\0') {
117-
hostname_len = (uint8_t)strnlen(hostname, DP_IFACE_HOSTNAME_MAX_LEN - 1);
118-
119-
if (DP_FAILED(add_dhcp_option(&pos, end, DHCP_OPT_HOSTNAME, hostname, hostname_len)))
113+
if (port->iface.hostname_len > 0)
114+
if (DP_FAILED(add_dhcp_option(&pos, end, DHCP_OPT_HOSTNAME, port->iface.cfg.hostname, (u_int8_t)port->iface.hostname_len)))
120115
return DP_ERROR;
121-
}
122116

123117
if (pos >= end)
124118
return DP_ERROR;
@@ -190,7 +184,6 @@ static __rte_always_inline rte_edge_t get_next_index(struct rte_node *node, stru
190184
rte_be32_t pxe_srv_ip;
191185
char pxe_srv_ip_str[INET6_ADDRSTRLEN];
192186
uint8_t response_type;
193-
const char *hostname;
194187

195188
incoming_eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
196189
incoming_ipv4_hdr = (struct rte_ipv4_hdr *)(incoming_eth_hdr + 1);
@@ -274,8 +267,7 @@ static __rte_always_inline rte_edge_t get_next_index(struct rte_node *node, stru
274267
dhcp_hdr->siaddr = server_ip;
275268
}
276269

277-
hostname = port->iface.cfg.hostname;
278-
options_len = add_dhcp_options(dhcp_hdr, response_type, pxe_mode, hostname);
270+
options_len = add_dhcp_options(dhcp_hdr, response_type, pxe_mode, port);
279271
if (DP_FAILED(options_len)) {
280272
DPNODE_LOG_WARNING(node, "DHCP response options too large for a packet");
281273
return DHCP_NEXT_DROP;

test/local/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ def create(vni):
132132
vm.ip = f"{ov_ip_prefix}{vni}.1.{VMSpec._idx+1}"
133133
vm.ipv6 = f"{ov_ipv6_prefix}{vni}:1::{VMSpec._idx+1}"
134134
vm.ul_ipv6 = None # will be assigned dynamically
135+
vm.hostname = None
135136
VMSpec._idx += 1
136137
return vm
138+
def set_hostname(self, hostname):
139+
self.hostname = hostname
137140

138141
PF0 = PFSpec.create()
139142
PF1 = PFSpec.create()
140143
# VM1 and VM2 are on the same VNI
141144
VM1 = VMSpec.create(vni1)
145+
VM1.set_hostname("vm1-host")
142146
VM2 = VMSpec.create(vni1)
143147
# VM3 is on the second VNI
144148
VM3 = VMSpec.create(vni2)

test/local/dp_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def init_ifaces(self, grpc_client):
8686
if not self.hardware: # see above
8787
interface_init(PF1.tap, self.port_redundancy)
8888
grpc_client.init()
89-
VM1.ul_ipv6 = grpc_client.addinterface(VM1.name, VM1.pci, VM1.vni, VM1.ip, VM1.ipv6, pxe_server, ipxe_file_name, hostname=VM1.name)
89+
VM1.ul_ipv6 = grpc_client.addinterface(VM1.name, VM1.pci, VM1.vni, VM1.ip, VM1.ipv6, pxe_server, ipxe_file_name, hostname=VM1.hostname)
9090
VM2.ul_ipv6 = grpc_client.addinterface(VM2.name, VM2.pci, VM2.vni, VM2.ip, VM2.ipv6, pxe_server, ipxe_file_name)
91-
VM3.ul_ipv6 = grpc_client.addinterface(VM3.name, VM3.pci, VM3.vni, VM3.ip, VM3.ipv6, hostname=VM3.name)
91+
VM3.ul_ipv6 = grpc_client.addinterface(VM3.name, VM3.pci, VM3.vni, VM3.ip, VM3.ipv6)
9292
grpc_client.addroute(vni1, neigh_vni1_ov_ip_route, 0, neigh_vni1_ul_ipv6)
9393
grpc_client.addroute(vni1, neigh_vni1_ov_ipv6_route, 0, neigh_vni1_ul_ipv6)
9494
grpc_client.addroute(vni1, "0.0.0.0/0", vni1, router_ul_ipv6)

test/local/helpers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from config import *
1313

1414

15-
def request_ip(vm, check_hostname=False):
15+
def request_ip(vm):
1616
scapy.config.conf.checkIPaddr = False
1717
answer = dhcp_request(iface=vm.tap, timeout=sniff_timeout)
1818
validate_checksums(answer)
@@ -27,11 +27,10 @@ def request_ip(vm, check_hostname=False):
2727
if not dns_servers or dhcp_dns1 not in dns_servers or dhcp_dns2 not in dns_servers:
2828
raise AssertionError(f"DHCP message does not specify the right DNS servers: {dns_servers} instead of {dhcp_dns1} and {dhcp_dns2}")
2929

30-
# Check for hostname option
31-
if check_hostname:
30+
if vm.hostname != None:
3231
hostname_option = next((opt[1] for opt in options if opt[0] == 'hostname'), None)
3332
assert hostname_option is not None, "Hostname option not in DHCP reply"
34-
expected_hostname = vm.name
33+
expected_hostname = vm.hostname
3534
assert hostname_option.decode('utf-8') == expected_hostname, \
3635
f"DHCP reply does not specify the correct hostname: {hostname_option.decode('utf-8')} instead of {expected_hostname}"
3736

test/local/test_dhcpv4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from helpers import *
55

66
def test_dhcpv4_vf0(prepare_ifaces):
7-
request_ip(VM1, check_hostname=True)
7+
request_ip(VM1)
88

99
def test_dhcpv4_vf1(prepare_ifaces):
1010
request_ip(VM2)

0 commit comments

Comments
 (0)