DHCPv[46] proxy tests

Change-Id: I6aaf9c602cd515ed9d4416d286f9191d048c1a87
Signed-off-by: Neale Ranns <nranns@cisco.com>
This commit is contained in:
Neale Ranns
2017-01-13 07:57:46 -08:00
parent dc90d423a5
commit fca0c242e4
5 changed files with 911 additions and 19 deletions

View File

@ -703,6 +703,12 @@ int dhcp_proxy_set_server_2 (ip4_address_t *addr, ip4_address_t *src_address,
dhcp_server_t * server = 0;
u32 server_index = 0;
u32 rx_fib_index = 0;
const fib_prefix_t all_1s =
{
.fp_len = 32,
.fp_addr.ip4.as_u32 = 0xffffffff,
.fp_proto = FIB_PROTOCOL_IP4,
};
if (addr->as_u32 == 0)
return VNET_API_ERROR_INVALID_DST_ADDRESS;
@ -720,8 +726,18 @@ int dhcp_proxy_set_server_2 (ip4_address_t *addr, ip4_address_t *src_address,
if (is_del)
{
memset (server, 0, sizeof (*server));
return 0;
fib_table_entry_special_remove(rx_fib_index,
&all_1s,
FIB_SOURCE_DHCP);
return 0;
}
if (!server->valid)
fib_table_entry_special_add(rx_fib_index,
&all_1s,
FIB_SOURCE_DHCP,
FIB_ENTRY_FLAG_LOCAL,
ADJ_INDEX_INVALID);
goto initialize_it;
}
@ -738,6 +754,11 @@ int dhcp_proxy_set_server_2 (ip4_address_t *addr, ip4_address_t *src_address,
server = pool_elt_at_index (dpm->dhcp_servers, server_index);
memset (server, 0, sizeof (*server));
pool_put (dpm->dhcp_servers, server);
fib_table_entry_special_remove(rx_fib_index,
&all_1s,
FIB_SOURCE_DHCP);
return 0;
}
@ -752,9 +773,16 @@ int dhcp_proxy_set_server_2 (ip4_address_t *addr, ip4_address_t *src_address,
}
pool_get (dpm->dhcp_servers, server);
fib_table_entry_special_add(rx_fib_index,
&all_1s,
FIB_SOURCE_DHCP,
FIB_ENTRY_FLAG_LOCAL,
ADJ_INDEX_INVALID);
initialize_it:
server->dhcp_server.as_u32 = addr->as_u32;
server->server_fib_index =
fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4,

View File

@ -0,0 +1,58 @@
diff --git a/scapy/layers/dhcp6.py b/scapy/layers/dhcp6.py
index 4cb9291..a1adcfc 100644
--- a/scapy/layers/dhcp6.py
+++ b/scapy/layers/dhcp6.py
@@ -74,7 +74,9 @@ dhcp6opts = { 1: "CLIENTID",
36: "OPTION_GEOCONF_CIVIC", #RFC-ietf-geopriv-dhcp-civil-09.txt
37: "OPTION_REMOTE_ID", #RFC4649
38: "OPTION_SUBSCRIBER_ID", #RFC4580
- 39: "OPTION_CLIENT_FQDN" } #RFC4704
+ 39: "OPTION_CLIENT_FQDN", #RFC4704
+ 68: "OPTION_VSS", #RFC6607
+ 79: "OPTION_CLIENT_LINKLAYER_ADDR" } #RFC6939
dhcp6opts_by_code = { 1: "DHCP6OptClientId",
2: "DHCP6OptServerId",
@@ -116,12 +118,14 @@ dhcp6opts_by_code = { 1: "DHCP6OptClientId",
#40: "DHCP6OptPANAAgent", #RFC-ietf-dhc-paa-option-05.txt
#41: "DHCP6OptNewPOSIXTimeZone, #RFC4833
#42: "DHCP6OptNewTZDBTimeZone, #RFC4833
- 43: "DHCP6OptRelayAgentERO" #RFC4994
+ 43: "DHCP6OptRelayAgentERO", #RFC4994
#44: "DHCP6OptLQQuery", #RFC5007
#45: "DHCP6OptLQClientData", #RFC5007
#46: "DHCP6OptLQClientTime", #RFC5007
#47: "DHCP6OptLQRelayData", #RFC5007
#48: "DHCP6OptLQClientLink", #RFC5007
+ 68: "DHCP6OptVSS", #RFC6607
+ 79: "DHCP6OptClientLinkLayerAddr", #RFC6939
}
@@ -838,6 +842,26 @@ class DHCP6OptRelayAgentERO(_DHCP6OptGuessPayload): # RFC4994
_OptReqListField("reqopts", [23, 24],
length_from = lambda pkt: pkt.optlen) ]
+# "Client link-layer address type. The link-layer type MUST be a valid hardware
+# type assigned by the IANA, as described in [RFC0826]
+class DHCP6OptClientLinkLayerAddr(_DHCP6OptGuessPayload): #RFC6939
+ name = "DHCP6 Option - Client Link Layer address"
+ fields_desc = [ ShortEnumField("optcode", 79, dhcp6opts),
+ FieldLenField("optlen", None, length_of="clladdr",
+ adjust = lambda pkt,x: x+1),
+ ShortField("lltype", 1), # ethernet
+ _LLAddrField("clladdr", ETHER_ANY) ]
+
+# Virtual Subnet selection
+class DHCP6OptVSS(_DHCP6OptGuessPayload): #RFC6607
+ name = "DHCP6 Option - Virtual Subnet Selection"
+ fields_desc = [ ShortEnumField("optcode", 68, dhcp6opts),
+ FieldLenField("optlen", None, length_of="data",
+ adjust = lambda pkt,x: x+1),
+ ByteField("type", 255), # Default Global/default table
+ StrLenField("data", "",
+ length_from = lambda pkt: pkt.optlen) ]
+
#####################################################################
### DHCPv6 messages ###
#####################################################################

739
test/test_dhcp.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -19,12 +19,16 @@ class RoutePath:
nh_sw_if_index,
nh_table_id=0,
labels=[],
nh_via_label=MPLS_LABEL_INVALID):
self.nh_addr = socket.inet_pton(socket.AF_INET, nh_addr)
nh_via_label=MPLS_LABEL_INVALID,
is_ip6=0):
self.nh_itf = nh_sw_if_index
self.nh_table_id = nh_table_id
self.nh_via_label = nh_via_label
self.nh_labels = labels
if is_ip6:
self.nh_addr = socket.inet_pton(socket.AF_INET6, nh_addr)
else:
self.nh_addr = socket.inet_pton(socket.AF_INET, nh_addr)
class IpRoute:
@ -33,34 +37,61 @@ class IpRoute:
"""
def __init__(self, test, dest_addr,
dest_addr_len, paths, table_id=0):
dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0):
self._test = test
self.paths = paths
self.dest_addr = socket.inet_pton(socket.AF_INET, dest_addr)
self.dest_addr_len = dest_addr_len
self.table_id = table_id
self.is_ip6 = is_ip6
self.is_local = is_local
if is_ip6:
self.dest_addr = socket.inet_pton(socket.AF_INET6, dest_addr)
else:
self.dest_addr = socket.inet_pton(socket.AF_INET, dest_addr)
def add_vpp_config(self):
for path in self.paths:
if self.is_local:
self._test.vapi.ip_add_del_route(
self.dest_addr,
self.dest_addr_len,
path.nh_addr,
path.nh_itf,
socket.inet_pton(socket.AF_INET6, "::"),
0xffffffff,
is_local=1,
table_id=self.table_id,
next_hop_out_label_stack=path.nh_labels,
next_hop_n_out_labels=len(
path.nh_labels),
next_hop_via_label=path.nh_via_label)
is_ipv6=self.is_ip6)
else:
for path in self.paths:
self._test.vapi.ip_add_del_route(
self.dest_addr,
self.dest_addr_len,
path.nh_addr,
path.nh_itf,
table_id=self.table_id,
next_hop_out_label_stack=path.nh_labels,
next_hop_n_out_labels=len(
path.nh_labels),
next_hop_via_label=path.nh_via_label,
is_ipv6=self.is_ip6)
def remove_vpp_config(self):
for path in self.paths:
self._test.vapi.ip_add_del_route(self.dest_addr,
self.dest_addr_len,
path.nh_addr,
path.nh_itf,
table_id=self.table_id,
is_add=0)
if self.is_local:
self._test.vapi.ip_add_del_route(
self.dest_addr,
self.dest_addr_len,
socket.inet_pton(socket.AF_INET6, "::"),
0xffffffff,
is_local=1,
is_add=0,
table_id=self.table_id,
is_ipv6=self.is_ip6)
else:
for path in self.paths:
self._test.vapi.ip_add_del_route(self.dest_addr,
self.dest_addr_len,
path.nh_addr,
path.nh_itf,
table_id=self.table_id,
is_add=0)
class MplsIpBind:

View File

@ -1142,3 +1142,39 @@ class VppPapiProvider(object):
'template_interval': template_interval,
'udp_checksum': udp_checksum,
})
def dhcp_proxy_config(self,
dhcp_server,
dhcp_src_address,
rx_table_id=0,
server_table_id=0,
is_add=1,
is_ipv6=0,
insert_circuit_id=0):
return self.api(
self.papi.dhcp_proxy_config_2,
{
'rx_vrf_id': rx_table_id,
'server_vrf_id': server_table_id,
'is_ipv6': is_ipv6,
'is_add': is_add,
'insert_circuit_id': insert_circuit_id,
'dhcp_server': dhcp_server,
'dhcp_src_address': dhcp_src_address,
})
def dhcp_proxy_set_vss(self,
table_id,
fib_id,
oui,
is_add=1,
is_ip6=0):
return self.api(
self.papi.dhcp_proxy_set_vss,
{
'tbl_id': table_id,
'fib_id': fib_id,
'is_ipv6': is_ip6,
'is_add': is_add,
'oui': oui,
})