使用 OVN 设置 DHCP

使用 OVN 设置 DHCP

我正在尝试设置一个类似于描述的环境这里其中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和的两个机箱上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

Onovn1是开关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"}

ovn1port1已被添加到名为 的网络命名空间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 地址匹配。

如果我在该网络命名空间中针对端口 1 运行 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 "" */

答案1

我最终想通了。我整理了一份完整的文章https://blog.oddbit.com/post/2019-12-19-ovn-and-dhcp/贯穿整个过程。

我认为我之前测试中的关键问题是,为了让 OVN DHCP 服务响应,你必须在条目中设置一些强制选项dhcp_options。这些选项没有记录在任何地方,但如果我们看看来源我们看:

    const char *server_ip = smap_get(
        &op->nbsp->dhcpv4_options->options, "server_id");
    const char *server_mac = smap_get(
        &op->nbsp->dhcpv4_options->options, "server_mac");
    const char *lease_time = smap_get(
        &op->nbsp->dhcpv4_options->options, "lease_time");

    if (!(server_ip && server_mac && lease_time)) {
        /* "server_id", "server_mac" and "lease_time" should be
         * present in the dhcp_options. */
        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
        VLOG_WARN_RL(&rl, "Required DHCPv4 options not defined for lport - %s",
                     op->json_key);
        return false;
    }

因此,我们必须设置server_idserver_mac和。我在之前的测试中lease_time遗漏了这一点。server_mac

相关内容