Skip to content

Commit e991c65

Browse files
committed
CP-312082: [xapi] Push LLDP config to networkd in Nm.bring_pif_up
When bringing up the NIC of a managed physical PIF, build the networkd LLDP record from the XAPI database and include it in the interface configuration passed to networkd, replacing the previous hard-coded 'lldp = None'. The effective state resolves the configuration matrix: PIF.lldp_mode of enabled/disabled overrides pool.lldp_enabled, and 'enabled' additionally sets 'force' so networkd overrides its NIC-driver blocklist. The chassis id, system name and description are taken from the host, and the multicast address from pool.lldp_multicast_address. For bond members, the bond master is plugged then the lldp settings of physical PIFs can take effect. Signed-off-by: Changlei Li <changlei.li@citrix.com>
1 parent 8a8ad43 commit e991c65

3 files changed

Lines changed: 60 additions & 7 deletions

File tree

ocaml/xapi/nm.ml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,42 @@ let determine_other_config ~__context pif_rc net_rc =
119119
(pool_oc |> Listext.update_assoc net_oc |> Listext.update_assoc pif_oc)
120120
@ additional
121121

122+
(* Build the LLDP configuration to push to networkd for the NIC of a managed
123+
physical PIF. The effective state follows the configuration matrix: an
124+
explicit PIF.lldp_mode of enabled/disabled overrides the pool-wide
125+
pool.lldp_enabled, and 'enabled' additionally sets 'force' to override the
126+
networkd driver blocklist. *)
127+
let determine_lldp ~__context pif_rc =
128+
let pool = Helpers.get_pool ~__context in
129+
let host = pif_rc.API.pIF_host in
130+
let enabled, force =
131+
match pif_rc.API.pIF_lldp_mode with
132+
| `enabled ->
133+
(true, true)
134+
| `disabled ->
135+
(false, false)
136+
| `default ->
137+
(Db.Pool.get_lldp_enabled ~__context ~self:pool, false)
138+
in
139+
let address =
140+
match Db.Pool.get_lldp_multicast_address ~__context ~self:pool with
141+
| `nearestbridge ->
142+
Nearest_bridge
143+
| `nearestnontpmrbridge ->
144+
Nearest_non_tpmr_bridge
145+
| `nearestcustomerbridge ->
146+
Nearest_customer_bridge
147+
in
148+
Some
149+
{
150+
force
151+
; chassis_id= Db.Host.get_uuid ~__context ~self:host
152+
; system_name= Db.Host.get_name_label ~__context ~self:host
153+
; system_description= Db.Host.get_name_description ~__context ~self:host
154+
; enabled
155+
; address= [address]
156+
}
157+
122158
let create_bond ~__context bond mtu persistent =
123159
(* Get all information we need from the DB before doing anything that may drop our
124160
* management connection *)
@@ -144,6 +180,7 @@ let create_bond ~__context bond mtu persistent =
144180
; ethtool_settings
145181
; ethtool_offload
146182
; persistent_i= persistent
183+
; lldp= determine_lldp ~__context (Db.PIF.get_record ~__context ~self:pif)
147184
}
148185
in
149186
(device, bridge, config)
@@ -436,6 +473,7 @@ let rec create_bridges ~__context pif_rc net_rc =
436473
; ethtool_settings
437474
; ethtool_offload
438475
; persistent_i= persistent
476+
; lldp= determine_lldp ~__context pif_rc
439477
}
440478
)
441479
]

ocaml/xapi/xapi_pif.ml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,26 +961,38 @@ let set_primary_address_type ~__context ~self ~primary_address_type =
961961
Monitor_dbcalls_cache.clear_cache_for_pif
962962
~pif_name:(Db.PIF.get_device ~__context ~self)
963963

964-
(* LLDP is only configurable on managed physical PIFs that are not bond
965-
slaves; bond masters, VLAN, tunnel and SR-IOV PIFs are excluded. *)
964+
(* LLDP is configurable on any managed physical PIF, i.e. a standalone
965+
physical NIC or a bond member NIC. Bond masters, VLAN, tunnel and SR-IOV
966+
PIFs are excluded, as they do not represent a physical NIC. *)
966967
let assert_lldp_configurable ~__context ~self =
967968
Xapi_pif_helpers.assert_pif_is_managed ~__context ~self ;
968969
let pif_rec = Db.PIF.get_record ~__context ~self in
969970
match Xapi_pif_helpers.get_pif_type pif_rec with
970-
| Xapi_pif_helpers.Physical _ when pif_rec.API.pIF_bond_slave_of = Ref.null ->
971+
| Xapi_pif_helpers.Physical _ ->
971972
()
972973
| _ ->
973974
raise
974975
(Api_errors.Server_error
975976
(Api_errors.pif_is_not_physical, [Ref.string_of self])
976977
)
977978

979+
(* LLDP runs on the physical NIC. A standalone physical PIF is plugged
980+
directly; a bond member's configuration is applied by (re)plugging the
981+
bond master, which brings its member NICs up. *)
982+
let pif_to_plug_for_lldp ~__context ~self =
983+
match Db.PIF.get_bond_slave_of ~__context ~self with
984+
| bond when bond <> Ref.null ->
985+
Db.Bond.get_master ~__context ~self:bond
986+
| _ ->
987+
self
988+
978989
let set_lldp_mode ~__context ~self ~value ~force =
979990
assert_lldp_configurable ~__context ~self ;
980991
if force || Db.PIF.get_lldp_mode ~__context ~self <> value then (
981992
Db.PIF.set_lldp_mode ~__context ~self ~value ;
993+
let to_plug = pif_to_plug_for_lldp ~__context ~self in
982994
Helpers.call_api_functions ~__context (fun rpc session_id ->
983-
Client.Client.PIF.plug ~rpc ~session_id ~self
995+
Client.Client.PIF.plug ~rpc ~session_id ~self:to_plug
984996
)
985997
)
986998

ocaml/xapi/xapi_pool.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,13 +3860,16 @@ let set_igmp_snooping_enabled ~__context ~self ~value =
38603860
let set_lldp_enabled ~__context ~self ~value ~force =
38613861
if force || Db.Pool.get_lldp_enabled ~__context ~self <> value then (
38623862
Db.Pool.set_lldp_enabled ~__context ~self ~value ;
3863-
(* LLDP applies only to managed physical PIFs that are not bond slaves. *)
3863+
(* LLDP runs on physical NICs. Standalone physical PIFs are plugged
3864+
directly; bonded NICs are (re)configured by plugging the bond master.
3865+
Both apply the per-PIF PIF.lldp_mode against the new pool setting. *)
38643866
let pifs =
38653867
Db.PIF.get_all_records ~__context
38663868
|> List.filter (fun (_, r) ->
38673869
r.API.pIF_managed
3868-
&& r.API.pIF_physical
3869-
&& r.API.pIF_bond_slave_of = Ref.null
3870+
&& (r.API.pIF_physical && r.API.pIF_bond_slave_of = Ref.null
3871+
|| r.API.pIF_bond_master_of <> []
3872+
)
38703873
)
38713874
|> List.map fst
38723875
in

0 commit comments

Comments
 (0)