我正在尝试设置一个类似于此处描述的环境,其中 OVN 将为逻辑网络提供 DHCP 服务。
我有一个名为 `net0 的逻辑交换机,有两个端口:
[root@ovn0 ~]# ovn-nbctl show
[root@ovn0 ~]# ovn-nbctl show
switch 0507d649-0730-4fdc-95cd-943b25e613ab (net0
port port2
addresses: ["c0:ff:ee:00:00:12 10.0.0.12"]
port port1
addresses: ["c0:ff:ee:00:00:11 10.0.0.11"]
这些端口绑定在两个名为ovn1
and的机箱上ovn2
:
[root@ovn0 ~]# ovn-sbctl show
Chassis ovn0
hostname: ovn0.virt
Encap geneve
ip: "192.168.122.80"
options: {csum="true"}
Chassis ovn1
hostname: ovn1.virt
Encap geneve
ip: "192.168.122.99"
options: {csum="true"}
Port_Binding port1
Chassis ovn2
hostname: ovn2.virt
Encap geneve
ip: "192.168.122.109"
options: {csum="true"}
Port_Binding port2
On ovn1
,port1
是br-int
开关的一部分:
[root@ovn1 ~]# ovs-vsctl list-ports br-int
ovn-ovn0-0
ovn-ovn2-0
port1
它有适当的iface-id
:
[root@ovn1 ~]# ovs-vsctl list interface port1 |egrep -v '\[]|{}'
_uuid : 63101ec6-be8c-4df7-bdab-e43f8bc4f7f9
admin_state : up
external_ids : {iface-id="port1"}
ifindex : 0
ingress_policing_burst: 0
ingress_policing_rate: 0
link_resets : 1
link_state : up
mac : "c0:ff:ee:00:00:11"
mac_in_use : "c0:ff:ee:00:00:11"
mtu : 1500
name : "port1"
ofport : 2
statistics : {collisions=0, rx_bytes=0, rx_crc_err=0, rx_dropped=0, rx_errors=0, rx_frame_err=0, rx_over_err=0, rx_packets=0, tx_bytes=3672, tx_dropped=0, tx_errors=0, tx_packets=20}
status : {driver_name=openvswitch}
type : internal
我已经在该端口上配置了 dhcp 选项:
[root@ovn0 ~]# ovn-nbctl lsp-get-dhcpv4-options port1
29f9e321-93d1-4974-8cd7-7f65ad376f51 (10.0.0.0/24)
哪个地图:
[root@ovn0 ~]# ovn-nbctl list dhcp_options
_uuid : 29f9e321-93d1-4974-8cd7-7f65ad376f51
cidr : "10.0.0.0/24"
external_ids : {}
options : {lease_time="3600", router="10.0.0.1", server_id="10.0.0.1"}
On ovn1
,port1
已添加到名为 的网络命名空间中vm1
:
[root@ovn1 ~]# ip netns exec vm1 ip addr
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
6: port1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether c0:ff:ee:00:00:11 brd ff:ff:ff:ff:ff:ff
inet6 fe80::2c8b:65ff:fe00:4/64 scope link
valid_lft forever preferred_lft forever
MAC 地址与之前在逻辑端口数据库中配置的 MAC 地址相匹配。
如果我在该网络命名空间中针对 port1 运行 dhcp 客户端,它永远不会得到回复:
[root@ovn1 ~]# ip netns exec vm1 dhclient -d port1
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/port1/c0:ff:ee:00:00:11
Sending on LPF/port1/c0:ff:ee:00:00:11
Sending on Socket/fallback
DHCPDISCOVER on port1 to 255.255.255.255 port 67 interval 7 (xid=0x75a05a70)
DHCPDISCOVER on port1 to 255.255.255.255 port 67 interval 21 (xid=0x75a05a70)
.
.
.
No DHCPOFFERS received.
让 OVN 响应此端口上的 DHCP 请求还需要什么?
更新 1
ovn-trace
建议 dhcp 请求只是广播出所有接口:
[root@ovn0 ~]# ovn-trace net0 'inport=="port1" && eth.src==c0:ff:ee:00:00:11 && ip4.src==0.0.0.0 && eth.dst==ff:ff:ff:ff:ff:ff && ip4.dst==255.255.255.255 && udp.src==68 && udp.dst==67'
# udp,reg14=0x2,vlan_tci=0x0000,dl_src=c0:ff:ee:00:00:11,dl_dst=ff:ff:ff:ff:ff:ff,nw_src=0.0.0.0,nw_dst=255.255.255.255,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=68,tp_dst=67
ingress(dp="net0", inport="port1")
----------------------------------
0. ls_in_port_sec_l2 (ovn-northd.c:4028): inport == "port1" && eth.src == {c0:ff:ee:00:00:11}, priority 50, uuid e155c87e
next;
1. ls_in_port_sec_ip (ovn-northd.c:3642): inport == "port1" && eth.src == c0:ff:ee:00:00:11 && ip4.src == 0.0.0.0 && ip4.dst == 255.255.255.255 && udp.src == 68 && udp.dst == 67, priority 90, uuid 5548c089
next;
17. ls_in_l2_lkup (ovn-northd.c:5678): eth.mcast, priority 70, uuid 51b48b77
outport = "_MC_flood";
output;
multicast(dp="net0", mcgroup="_MC_flood")
-----------------------------------------
egress(dp="net0", inport="port1", outport="net0-gw")
----------------------------------------------------
9. ls_out_port_sec_l2 (ovn-northd.c:4115): eth.mcast, priority 100, uuid 7db51d27
output;
/* output to "net0-gw", type "" */
egress(dp="net0", inport="port1", outport="port1")
--------------------------------------------------
/* omitting output because inport == outport && !flags.loopback */
egress(dp="net0", inport="port1", outport="port2")
--------------------------------------------------
9. ls_out_port_sec_l2 (ovn-northd.c:4115): eth.mcast, priority 100, uuid 7db51d27
output;
/* output to "port2", type "" */
我最终想通了。我在https://blog.oddbit.com/post/2019-12-19-ovn-and-dhcp/上整理了一篇完整的文章,介绍了整个过程。
我认为我之前测试中的关键问题是,为了让 OVN DHCP 服务响应,您必须在
dhcp_options
条目中设置一些强制选项。这些都没有记录在任何地方,但是如果我们查看源代码,我们会看到:因此,我们必须设置
server_id
、server_mac
和lease_time
。server_mac
我在之前的测试中丢失了。