Skip to content

Commit 8df1be2

Browse files
Wilson Pengovsrobot
authored andcommitted
netdev-windows: Force update ifi_flags for internal port.
This fix could solve the issue for not updated ifi_flags and mac of internal type port which may could not get the correct ifi_flags and mac info when the internal type port is created on Windows platform. With the patch, if user is removing some network adapter via CMD below, OVS on Windows could also update the value of fields admin_state and link_state as "down". Related MAC is also set zero. Remove-VMNetworkAdapter -ManagementOS -SwitchName br-int -VMNetworkAdapterName xxx As in ovs-windows it is not set ifindex on ovs interface, it may need another patch to address the not-implemented ifIndex which could be got via CMD ovs-vsctl list interface. Reported-at:openvswitch/ovs-issues#351 Reported-at:openvswitch/ovs-issues#353 Signed-off-by: Wilson Peng <[email protected]> Signed-off-by: 0-day Robot <[email protected]>
1 parent 2100a04 commit 8df1be2

File tree

2 files changed

+96
-15
lines changed

2 files changed

+96
-15
lines changed

lib/dpif-netlink.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,10 @@ dpif_netlink_run(struct dpif *dpif_)
751751
dpif_netlink_refresh_handlers_vport_dispatch(dpif,
752752
dpif->n_handlers);
753753
fat_rwlock_unlock(&dpif->upcall_lock);
754+
#ifdef _WIN32
755+
seq_change(connectivity_seq_get());
756+
VLOG_INFO("Do seq_change for connectivity_seq");
757+
#endif
754758
}
755759
}
756760
return false;

lib/netdev-windows.c

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ netdev_windows_system_construct(struct netdev *netdev_)
173173
type = netdev_get_type(&netdev->up);
174174
if (type && !strcmp(type, "system") &&
175175
(info.ovs_type == OVS_VPORT_TYPE_INTERNAL)) {
176-
VLOG_DBG("construct device %s, ovs_type: %u failed",
176+
VLOG_ERR("construct device %s, ovs_type: %u failed",
177177
netdev_get_name(&netdev->up), info.ovs_type);
178178
return 1;
179179
}
@@ -183,15 +183,18 @@ netdev_windows_system_construct(struct netdev *netdev_)
183183
netdev->port_no = info.port_no;
184184

185185
netdev->mac = info.mac_address;
186-
netdev->cache_valid = VALID_ETHERADDR;
186+
if (!eth_addr_is_zero(netdev->mac)) {
187+
netdev->cache_valid = VALID_ETHERADDR;
188+
}
187189
netdev->ifindex = -EOPNOTSUPP;
188190

189191
netdev->mtu = info.mtu;
190192
netdev->cache_valid |= VALID_MTU;
191193

192194
netdev->ifi_flags = dp_to_netdev_ifi_flags(info.ifi_flags);
193-
netdev->cache_valid |= VALID_IFFLAG;
194-
195+
if (netdev->ifi_flags) {
196+
netdev->cache_valid |= VALID_IFFLAG;
197+
}
195198
VLOG_DBG("construct device %s, ovs_type: %u.",
196199
netdev_get_name(&netdev->up), info.ovs_type);
197200
return 0;
@@ -330,14 +333,40 @@ netdev_windows_get_etheraddr(const struct netdev *netdev_,
330333
struct eth_addr *mac)
331334
{
332335
struct netdev_windows *netdev = netdev_windows_cast(netdev_);
336+
struct netdev_windows_netdev_info info;
337+
struct ofpbuf *buf = NULL;
338+
const char *type = NULL;
339+
const char *dev_name = NULL;
340+
int ret;
333341

334-
ovs_assert((netdev->cache_valid & VALID_ETHERADDR) != 0);
335342
if (netdev->cache_valid & VALID_ETHERADDR) {
336343
*mac = netdev->mac;
337-
} else {
338-
return EINVAL;
344+
return 0;
345+
} else if (eth_addr_is_zero(netdev->mac)) {
346+
type = netdev_get_type(&netdev->up);
347+
if (type && !strcmp(type, "internal")) {
348+
dev_name = netdev_get_name(&netdev->up);
349+
if (dev_name) {
350+
ret = query_netdev(dev_name, &info, &buf);
351+
if (!ret) {
352+
ofpbuf_delete(buf);
353+
*mac = info.mac_address;
354+
if (!eth_addr_is_zero(info.mac_address)) {
355+
netdev->mac = info.mac_address;
356+
netdev->cache_valid |= VALID_ETHERADDR;
357+
}
358+
VLOG_DBG("get_etheraddr query_netdev dev %s success",
359+
dev_name);
360+
return 0;
361+
} else {
362+
VLOG_ERR("get_etheraddr query_netdev dev %s failed",
363+
dev_name);
364+
*mac = eth_addr_zero;
365+
}
366+
}
367+
}
339368
}
340-
return 0;
369+
return EINVAL;
341370
}
342371

343372
static int
@@ -363,24 +392,72 @@ netdev_windows_set_etheraddr(const struct netdev *netdev_,
363392
return 0;
364393
}
365394

366-
/* This functionality is not really required by the datapath.
367-
* But vswitchd bringup expects this to be implemented. */
368395
static int
369396
netdev_windows_update_flags(struct netdev *netdev_,
370397
enum netdev_flags off,
371398
enum netdev_flags on,
372399
enum netdev_flags *old_flagsp)
373400
{
374401
struct netdev_windows *netdev = netdev_windows_cast(netdev_);
402+
struct netdev_windows_netdev_info info;
403+
struct ofpbuf *buf = NULL;
404+
const char *type = NULL;
405+
const char *dev_name = NULL;
406+
uint32_t ifi_flags = 0;
407+
int ret;
408+
409+
type = netdev_get_type(&netdev->up);
410+
if (type && !strcmp(type, "internal")) {
411+
dev_name = netdev_get_name(&netdev->up);
412+
if (dev_name) {
413+
ret = query_netdev(dev_name, &info, &buf);
414+
if (!ret) {
415+
ofpbuf_delete(buf);
416+
ifi_flags = dp_to_netdev_ifi_flags(info.ifi_flags);
417+
if (ifi_flags) {
418+
*old_flagsp = ifi_flags;
419+
netdev->ifi_flags = ifi_flags;
420+
netdev->cache_valid |= VALID_IFFLAG;
421+
}
422+
423+
if (eth_addr_is_zero(netdev->mac) &&
424+
!eth_addr_is_zero(info.mac_address)) {
425+
netdev->mac = info.mac_address;
426+
netdev->cache_valid |= VALID_ETHERADDR;
427+
}
428+
VLOG_DBG("update_flags query_netdev dev %s success: %d",
429+
dev_name, *old_flagsp);
430+
return 0;
431+
} else {
432+
VLOG_ERR("update_flags query_netdev dev %s failed",
433+
dev_name);
434+
*old_flagsp = 0;
435+
netdev->ifi_flags = 0;
436+
if (netdev->cache_valid & VALID_IFFLAG) {
437+
netdev->cache_valid &= ~VALID_IFFLAG;
438+
/* On ofproto_run() it will check port status
439+
* for any port whose netdev has changed
440+
* Here netdev_change_seq_changed would force do
441+
* update_port()
442+
*/
443+
netdev_change_seq_changed(&netdev->up);
444+
VLOG_INFO("update_flags failed; update_port for %s",
445+
dev_name);
446+
}
447+
if (!eth_addr_is_zero(netdev->mac)) {
448+
netdev->mac = eth_addr_zero;
449+
netdev->cache_valid &= ~VALID_ETHERADDR;
450+
}
451+
return 0;
452+
}
453+
}
454+
}
375455

376-
ovs_assert((netdev->cache_valid & VALID_IFFLAG) != 0);
377456
if (netdev->cache_valid & VALID_IFFLAG) {
378457
*old_flagsp = netdev->ifi_flags;
379-
/* Setting the interface flags is not supported. */
380-
} else {
381-
return EINVAL;
458+
return 0;
382459
}
383-
return 0;
460+
return EINVAL;
384461
}
385462

386463
/* Looks up in the ARP table entry for a given 'ip'. If it is found, the

0 commit comments

Comments
 (0)