2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <netinet/in.h>
27 #include "connectivity.h"
30 #include "dynamic-string.h"
31 #include "fatal-signal.h"
34 #include "netdev-dpdk.h"
35 #include "netdev-provider.h"
36 #include "netdev-vport.h"
38 #include "openflow/openflow.h"
40 #include "poll-loop.h"
48 VLOG_DEFINE_THIS_MODULE(netdev);
50 COVERAGE_DEFINE(netdev_received);
51 COVERAGE_DEFINE(netdev_sent);
52 COVERAGE_DEFINE(netdev_add_router);
53 COVERAGE_DEFINE(netdev_get_stats);
55 struct netdev_saved_flags {
56 struct netdev *netdev;
57 struct list node; /* In struct netdev's saved_flags_list. */
58 enum netdev_flags saved_flags;
59 enum netdev_flags saved_values;
62 /* Protects 'netdev_shash' and the mutable members of struct netdev. */
63 static struct ovs_mutex netdev_mutex = OVS_MUTEX_INITIALIZER;
65 /* All created network devices. */
66 static struct shash netdev_shash OVS_GUARDED_BY(netdev_mutex)
67 = SHASH_INITIALIZER(&netdev_shash);
69 /* Protects 'netdev_classes' against insertions or deletions.
71 * This is a recursive mutex to allow recursive acquisition when calling into
72 * providers. For example, netdev_run() calls into provider 'run' functions,
73 * which might reasonably want to call one of the netdev functions that takes
74 * netdev_class_mutex. */
75 static struct ovs_mutex netdev_class_mutex OVS_ACQ_BEFORE(netdev_mutex);
77 /* Contains 'struct netdev_registered_class'es. */
78 static struct hmap netdev_classes OVS_GUARDED_BY(netdev_class_mutex)
79 = HMAP_INITIALIZER(&netdev_classes);
81 struct netdev_registered_class {
82 struct hmap_node hmap_node; /* In 'netdev_classes', by class->type. */
83 const struct netdev_class *class;
84 atomic_int ref_cnt; /* Number of 'struct netdev's of this class. */
87 /* This is set pretty low because we probably won't learn anything from the
88 * additional log messages. */
89 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
91 static void restore_all_flags(void *aux OVS_UNUSED);
92 void update_device_args(struct netdev *, const struct shash *args);
95 netdev_n_rxq(const struct netdev *netdev)
101 netdev_is_pmd(const struct netdev *netdev)
103 return !strcmp(netdev->netdev_class->type, "dpdk");
107 netdev_initialize(void)
108 OVS_EXCLUDED(netdev_class_mutex, netdev_mutex)
110 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
112 if (ovsthread_once_start(&once)) {
113 ovs_mutex_init_recursive(&netdev_class_mutex);
115 fatal_signal_add_hook(restore_all_flags, NULL, NULL, true);
116 netdev_vport_patch_register();
119 netdev_register_provider(&netdev_linux_class);
120 netdev_register_provider(&netdev_internal_class);
121 netdev_register_provider(&netdev_tap_class);
122 netdev_vport_tunnel_register();
124 #if defined(__FreeBSD__) || defined(__NetBSD__)
125 netdev_register_provider(&netdev_tap_class);
126 netdev_register_provider(&netdev_bsd_class);
128 netdev_dpdk_register();
130 ovsthread_once_done(&once);
134 /* Performs periodic work needed by all the various kinds of netdevs.
136 * If your program opens any netdevs, it must call this function within its
140 OVS_EXCLUDED(netdev_class_mutex, netdev_mutex)
142 struct netdev_registered_class *rc;
144 ovs_mutex_lock(&netdev_class_mutex);
145 HMAP_FOR_EACH (rc, hmap_node, &netdev_classes) {
146 if (rc->class->run) {
150 ovs_mutex_unlock(&netdev_class_mutex);
153 /* Arranges for poll_block() to wake up when netdev_run() needs to be called.
155 * If your program opens any netdevs, it must call this function within its
159 OVS_EXCLUDED(netdev_class_mutex, netdev_mutex)
161 struct netdev_registered_class *rc;
163 ovs_mutex_lock(&netdev_class_mutex);
164 HMAP_FOR_EACH (rc, hmap_node, &netdev_classes) {
165 if (rc->class->wait) {
169 ovs_mutex_unlock(&netdev_class_mutex);
172 static struct netdev_registered_class *
173 netdev_lookup_class(const char *type)
174 OVS_REQ_RDLOCK(netdev_class_mutex)
176 struct netdev_registered_class *rc;
178 HMAP_FOR_EACH_WITH_HASH (rc, hmap_node, hash_string(type, 0),
180 if (!strcmp(type, rc->class->type)) {
187 /* Initializes and registers a new netdev provider. After successful
188 * registration, new netdevs of that type can be opened using netdev_open(). */
190 netdev_register_provider(const struct netdev_class *new_class)
191 OVS_EXCLUDED(netdev_class_mutex, netdev_mutex)
195 ovs_mutex_lock(&netdev_class_mutex);
196 if (netdev_lookup_class(new_class->type)) {
197 VLOG_WARN("attempted to register duplicate netdev provider: %s",
201 error = new_class->init ? new_class->init() : 0;
203 struct netdev_registered_class *rc;
205 rc = xmalloc(sizeof *rc);
206 hmap_insert(&netdev_classes, &rc->hmap_node,
207 hash_string(new_class->type, 0));
208 rc->class = new_class;
209 atomic_init(&rc->ref_cnt, 0);
211 VLOG_ERR("failed to initialize %s network device class: %s",
212 new_class->type, ovs_strerror(error));
215 ovs_mutex_unlock(&netdev_class_mutex);
220 /* Unregisters a netdev provider. 'type' must have been previously
221 * registered and not currently be in use by any netdevs. After unregistration
222 * new netdevs of that type cannot be opened using netdev_open(). */
224 netdev_unregister_provider(const char *type)
225 OVS_EXCLUDED(netdev_class_mutex, netdev_mutex)
227 struct netdev_registered_class *rc;
230 ovs_mutex_lock(&netdev_class_mutex);
231 rc = netdev_lookup_class(type);
233 VLOG_WARN("attempted to unregister a netdev provider that is not "
234 "registered: %s", type);
235 error = EAFNOSUPPORT;
239 atomic_read(&rc->ref_cnt, &ref_cnt);
241 hmap_remove(&netdev_classes, &rc->hmap_node);
245 VLOG_WARN("attempted to unregister in use netdev provider: %s",
250 ovs_mutex_unlock(&netdev_class_mutex);
255 /* Clears 'types' and enumerates the types of all currently registered netdev
256 * providers into it. The caller must first initialize the sset. */
258 netdev_enumerate_types(struct sset *types)
259 OVS_EXCLUDED(netdev_mutex)
261 struct netdev_registered_class *rc;
266 ovs_mutex_lock(&netdev_class_mutex);
267 HMAP_FOR_EACH (rc, hmap_node, &netdev_classes) {
268 sset_add(types, rc->class->type);
270 ovs_mutex_unlock(&netdev_class_mutex);
273 /* Check that the network device name is not the same as any of the registered
274 * vport providers' dpif_port name (dpif_port is NULL if the vport provider
275 * does not define it) or the datapath internal port name (e.g. ovs-system).
277 * Returns true if there is a name conflict, false otherwise. */
279 netdev_is_reserved_name(const char *name)
280 OVS_EXCLUDED(netdev_mutex)
282 struct netdev_registered_class *rc;
286 ovs_mutex_lock(&netdev_class_mutex);
287 HMAP_FOR_EACH (rc, hmap_node, &netdev_classes) {
288 const char *dpif_port = netdev_vport_class_get_dpif_port(rc->class);
289 if (dpif_port && !strcmp(dpif_port, name)) {
290 ovs_mutex_unlock(&netdev_class_mutex);
294 ovs_mutex_unlock(&netdev_class_mutex);
296 if (!strncmp(name, "ovs-", 4)) {
301 dp_enumerate_types(&types);
302 SSET_FOR_EACH (type, &types) {
303 if (!strcmp(name+4, type)) {
304 sset_destroy(&types);
308 sset_destroy(&types);
314 /* Opens the network device named 'name' (e.g. "eth0") of the specified 'type'
315 * (e.g. "system") and returns zero if successful, otherwise a positive errno
316 * value. On success, sets '*netdevp' to the new network device, otherwise to
319 * Some network devices may need to be configured (with netdev_set_config())
320 * before they can be used. */
322 netdev_open(const char *name, const char *type, struct netdev **netdevp)
323 OVS_EXCLUDED(netdev_mutex)
325 struct netdev *netdev;
330 ovs_mutex_lock(&netdev_class_mutex);
331 ovs_mutex_lock(&netdev_mutex);
332 netdev = shash_find_data(&netdev_shash, name);
334 struct netdev_registered_class *rc;
336 rc = netdev_lookup_class(type && type[0] ? type : "system");
338 netdev = rc->class->alloc();
340 memset(netdev, 0, sizeof *netdev);
341 netdev->netdev_class = rc->class;
342 netdev->name = xstrdup(name);
343 netdev->node = shash_add(&netdev_shash, name, netdev);
345 /* By default enable one rx queue per netdev. */
346 if (netdev->netdev_class->rxq_alloc) {
351 list_init(&netdev->saved_flags_list);
353 error = rc->class->construct(netdev);
357 atomic_add(&rc->ref_cnt, 1, &old_ref_cnt);
358 seq_change(connectivity_seq_get());
361 ovs_assert(list_is_empty(&netdev->saved_flags_list));
362 shash_delete(&netdev_shash, netdev->node);
363 rc->class->dealloc(netdev);
369 VLOG_WARN("could not create netdev %s of unknown type %s",
371 error = EAFNOSUPPORT;
377 ovs_mutex_unlock(&netdev_mutex);
378 ovs_mutex_unlock(&netdev_class_mutex);
389 /* Returns a reference to 'netdev_' for the caller to own. Returns null if
390 * 'netdev_' is null. */
392 netdev_ref(const struct netdev *netdev_)
393 OVS_EXCLUDED(netdev_mutex)
395 struct netdev *netdev = CONST_CAST(struct netdev *, netdev_);
398 ovs_mutex_lock(&netdev_mutex);
399 ovs_assert(netdev->ref_cnt > 0);
401 ovs_mutex_unlock(&netdev_mutex);
406 /* Reconfigures the device 'netdev' with 'args'. 'args' may be empty
407 * or NULL if none are needed. */
409 netdev_set_config(struct netdev *netdev, const struct smap *args)
410 OVS_EXCLUDED(netdev_mutex)
412 if (netdev->netdev_class->set_config) {
413 const struct smap no_args = SMAP_INITIALIZER(&no_args);
416 error = netdev->netdev_class->set_config(netdev,
417 args ? args : &no_args);
419 VLOG_WARN("%s: could not set configuration (%s)",
420 netdev_get_name(netdev), ovs_strerror(error));
423 } else if (args && !smap_is_empty(args)) {
424 VLOG_WARN("%s: arguments provided to device that is not configurable",
425 netdev_get_name(netdev));
430 /* Returns the current configuration for 'netdev' in 'args'. The caller must
431 * have already initialized 'args' with smap_init(). Returns 0 on success, in
432 * which case 'args' will be filled with 'netdev''s configuration. On failure
433 * returns a positive errno value, in which case 'args' will be empty.
435 * The caller owns 'args' and its contents and must eventually free them with
438 netdev_get_config(const struct netdev *netdev, struct smap *args)
439 OVS_EXCLUDED(netdev_mutex)
444 if (netdev->netdev_class->get_config) {
445 error = netdev->netdev_class->get_config(netdev, args);
456 const struct netdev_tunnel_config *
457 netdev_get_tunnel_config(const struct netdev *netdev)
458 OVS_EXCLUDED(netdev_mutex)
460 if (netdev->netdev_class->get_tunnel_config) {
461 return netdev->netdev_class->get_tunnel_config(netdev);
468 netdev_unref(struct netdev *dev)
469 OVS_RELEASES(netdev_mutex)
471 ovs_assert(dev->ref_cnt);
472 if (!--dev->ref_cnt) {
473 const struct netdev_class *class = dev->netdev_class;
474 struct netdev_registered_class *rc;
477 dev->netdev_class->destruct(dev);
479 shash_delete(&netdev_shash, dev->node);
481 dev->netdev_class->dealloc(dev);
482 ovs_mutex_unlock(&netdev_mutex);
484 ovs_mutex_lock(&netdev_class_mutex);
485 rc = netdev_lookup_class(class->type);
486 atomic_sub(&rc->ref_cnt, 1, &old_ref_cnt);
487 ovs_assert(old_ref_cnt > 0);
488 ovs_mutex_unlock(&netdev_class_mutex);
490 ovs_mutex_unlock(&netdev_mutex);
494 /* Closes and destroys 'netdev'. */
496 netdev_close(struct netdev *netdev)
497 OVS_EXCLUDED(netdev_mutex)
500 ovs_mutex_lock(&netdev_mutex);
501 netdev_unref(netdev);
505 /* Parses 'netdev_name_', which is of the form [type@]name into its component
506 * pieces. 'name' and 'type' must be freed by the caller. */
508 netdev_parse_name(const char *netdev_name_, char **name, char **type)
510 char *netdev_name = xstrdup(netdev_name_);
513 separator = strchr(netdev_name, '@');
517 *name = xstrdup(separator + 1);
520 *type = xstrdup("system");
524 /* Attempts to open a netdev_rxq handle for obtaining packets received on
525 * 'netdev'. On success, returns 0 and stores a nonnull 'netdev_rxq *' into
526 * '*rxp'. On failure, returns a positive errno value and stores NULL into
529 * Some kinds of network devices might not support receiving packets. This
530 * function returns EOPNOTSUPP in that case.*/
532 netdev_rxq_open(struct netdev *netdev, struct netdev_rxq **rxp, int id)
533 OVS_EXCLUDED(netdev_mutex)
537 if (netdev->netdev_class->rxq_alloc && id < netdev->n_rxq) {
538 struct netdev_rxq *rx = netdev->netdev_class->rxq_alloc();
542 error = netdev->netdev_class->rxq_construct(rx);
544 ovs_mutex_lock(&netdev_mutex);
546 ovs_mutex_unlock(&netdev_mutex);
551 netdev->netdev_class->rxq_dealloc(rx);
565 netdev_rxq_close(struct netdev_rxq *rx)
566 OVS_EXCLUDED(netdev_mutex)
569 struct netdev *netdev = rx->netdev;
570 netdev->netdev_class->rxq_destruct(rx);
571 netdev->netdev_class->rxq_dealloc(rx);
572 netdev_close(netdev);
576 /* Attempts to receive batch of packets from 'rx'.
578 * Returns EAGAIN immediately if no packet is ready to be received.
580 * Returns EMSGSIZE, and discards the packet, if the received packet is longer
581 * than 'ofpbuf_tailroom(buffer)'.
583 * It is advised that the tailroom of 'buffer' should be
584 * VLAN_HEADER_LEN bytes longer than the MTU to allow space for an
585 * out-of-band VLAN header to be added to the packet. At the very least,
586 * 'buffer' must have at least ETH_TOTAL_MIN bytes of tailroom.
588 * This function may be set to null if it would always return EOPNOTSUPP
591 netdev_rxq_recv(struct netdev_rxq *rx, struct ofpbuf **buffers, int *cnt)
595 retval = rx->netdev->netdev_class->rxq_recv(rx, buffers, cnt);
597 COVERAGE_INC(netdev_received);
602 /* Arranges for poll_block() to wake up when a packet is ready to be received
605 netdev_rxq_wait(struct netdev_rxq *rx)
607 rx->netdev->netdev_class->rxq_wait(rx);
610 /* Discards any packets ready to be received on 'rx'. */
612 netdev_rxq_drain(struct netdev_rxq *rx)
614 return (rx->netdev->netdev_class->rxq_drain
615 ? rx->netdev->netdev_class->rxq_drain(rx)
619 /* Sends 'buffer' on 'netdev'. Returns 0 if successful, otherwise a positive
620 * errno value. Returns EAGAIN without blocking if the packet cannot be queued
621 * immediately. Returns EMSGSIZE if a partial packet was transmitted or if
622 * the packet is too big or too small to transmit on the device.
624 * To retain ownership of 'buffer' caller can set may_steal to false.
626 * The kernel maintains a packet transmission queue, so the caller is not
627 * expected to do additional queuing of packets.
629 * Some network devices may not implement support for this function. In such
630 * cases this function will always return EOPNOTSUPP. */
632 netdev_send(struct netdev *netdev, struct ofpbuf *buffer, bool may_steal)
636 error = (netdev->netdev_class->send
637 ? netdev->netdev_class->send(netdev, buffer, may_steal)
640 COVERAGE_INC(netdev_sent);
645 /* Registers with the poll loop to wake up from the next call to poll_block()
646 * when the packet transmission queue has sufficient room to transmit a packet
647 * with netdev_send().
649 * The kernel maintains a packet transmission queue, so the client is not
650 * expected to do additional queuing of packets. Thus, this function is
651 * unlikely to ever be used. It is included for completeness. */
653 netdev_send_wait(struct netdev *netdev)
655 if (netdev->netdev_class->send_wait) {
656 netdev->netdev_class->send_wait(netdev);
660 /* Attempts to set 'netdev''s MAC address to 'mac'. Returns 0 if successful,
661 * otherwise a positive errno value. */
663 netdev_set_etheraddr(struct netdev *netdev, const uint8_t mac[ETH_ADDR_LEN])
665 return netdev->netdev_class->set_etheraddr(netdev, mac);
668 /* Retrieves 'netdev''s MAC address. If successful, returns 0 and copies the
669 * the MAC address into 'mac'. On failure, returns a positive errno value and
670 * clears 'mac' to all-zeros. */
672 netdev_get_etheraddr(const struct netdev *netdev, uint8_t mac[ETH_ADDR_LEN])
674 return netdev->netdev_class->get_etheraddr(netdev, mac);
677 /* Returns the name of the network device that 'netdev' represents,
678 * e.g. "eth0". The caller must not modify or free the returned string. */
680 netdev_get_name(const struct netdev *netdev)
685 /* Retrieves the MTU of 'netdev'. The MTU is the maximum size of transmitted
686 * (and received) packets, in bytes, not including the hardware header; thus,
687 * this is typically 1500 bytes for Ethernet devices.
689 * If successful, returns 0 and stores the MTU size in '*mtup'. Returns
690 * EOPNOTSUPP if 'netdev' does not have an MTU (as e.g. some tunnels do not).
691 * On other failure, returns a positive errno value. On failure, sets '*mtup'
694 netdev_get_mtu(const struct netdev *netdev, int *mtup)
696 const struct netdev_class *class = netdev->netdev_class;
699 error = class->get_mtu ? class->get_mtu(netdev, mtup) : EOPNOTSUPP;
702 if (error != EOPNOTSUPP) {
703 VLOG_DBG_RL(&rl, "failed to retrieve MTU for network device %s: "
704 "%s", netdev_get_name(netdev), ovs_strerror(error));
710 /* Sets the MTU of 'netdev'. The MTU is the maximum size of transmitted
711 * (and received) packets, in bytes.
713 * If successful, returns 0. Returns EOPNOTSUPP if 'netdev' does not have an
714 * MTU (as e.g. some tunnels do not). On other failure, returns a positive
717 netdev_set_mtu(const struct netdev *netdev, int mtu)
719 const struct netdev_class *class = netdev->netdev_class;
722 error = class->set_mtu ? class->set_mtu(netdev, mtu) : EOPNOTSUPP;
723 if (error && error != EOPNOTSUPP) {
724 VLOG_DBG_RL(&rl, "failed to set MTU for network device %s: %s",
725 netdev_get_name(netdev), ovs_strerror(error));
731 /* Returns the ifindex of 'netdev', if successful, as a positive number. On
732 * failure, returns a negative errno value.
734 * The desired semantics of the ifindex value are a combination of those
735 * specified by POSIX for if_nametoindex() and by SNMP for ifIndex. An ifindex
736 * value should be unique within a host and remain stable at least until
737 * reboot. SNMP says an ifindex "ranges between 1 and the value of ifNumber"
738 * but many systems do not follow this rule anyhow.
740 * Some network devices may not implement support for this function. In such
741 * cases this function will always return -EOPNOTSUPP.
744 netdev_get_ifindex(const struct netdev *netdev)
746 int (*get_ifindex)(const struct netdev *);
748 get_ifindex = netdev->netdev_class->get_ifindex;
750 return get_ifindex ? get_ifindex(netdev) : -EOPNOTSUPP;
753 /* Stores the features supported by 'netdev' into each of '*current',
754 * '*advertised', '*supported', and '*peer' that are non-null. Each value is a
755 * bitmap of "enum ofp_port_features" bits, in host byte order. Returns 0 if
756 * successful, otherwise a positive errno value. On failure, all of the
757 * passed-in values are set to 0.
759 * Some network devices may not implement support for this function. In such
760 * cases this function will always return EOPNOTSUPP. */
762 netdev_get_features(const struct netdev *netdev,
763 enum netdev_features *current,
764 enum netdev_features *advertised,
765 enum netdev_features *supported,
766 enum netdev_features *peer)
768 int (*get_features)(const struct netdev *netdev,
769 enum netdev_features *current,
770 enum netdev_features *advertised,
771 enum netdev_features *supported,
772 enum netdev_features *peer);
773 enum netdev_features dummy[4];
780 advertised = &dummy[1];
783 supported = &dummy[2];
789 get_features = netdev->netdev_class->get_features;
791 ? get_features(netdev, current, advertised, supported,
795 *current = *advertised = *supported = *peer = 0;
800 /* Returns the maximum speed of a network connection that has the NETDEV_F_*
801 * bits in 'features', in bits per second. If no bits that indicate a speed
802 * are set in 'features', returns 'default_bps'. */
804 netdev_features_to_bps(enum netdev_features features,
805 uint64_t default_bps)
808 F_1000000MB = NETDEV_F_1TB_FD,
809 F_100000MB = NETDEV_F_100GB_FD,
810 F_40000MB = NETDEV_F_40GB_FD,
811 F_10000MB = NETDEV_F_10GB_FD,
812 F_1000MB = NETDEV_F_1GB_HD | NETDEV_F_1GB_FD,
813 F_100MB = NETDEV_F_100MB_HD | NETDEV_F_100MB_FD,
814 F_10MB = NETDEV_F_10MB_HD | NETDEV_F_10MB_FD
817 return ( features & F_1000000MB ? UINT64_C(1000000000000)
818 : features & F_100000MB ? UINT64_C(100000000000)
819 : features & F_40000MB ? UINT64_C(40000000000)
820 : features & F_10000MB ? UINT64_C(10000000000)
821 : features & F_1000MB ? UINT64_C(1000000000)
822 : features & F_100MB ? UINT64_C(100000000)
823 : features & F_10MB ? UINT64_C(10000000)
827 /* Returns true if any of the NETDEV_F_* bits that indicate a full-duplex link
828 * are set in 'features', otherwise false. */
830 netdev_features_is_full_duplex(enum netdev_features features)
832 return (features & (NETDEV_F_10MB_FD | NETDEV_F_100MB_FD | NETDEV_F_1GB_FD
833 | NETDEV_F_10GB_FD | NETDEV_F_40GB_FD
834 | NETDEV_F_100GB_FD | NETDEV_F_1TB_FD)) != 0;
837 /* Set the features advertised by 'netdev' to 'advertise'. Returns 0 if
838 * successful, otherwise a positive errno value. */
840 netdev_set_advertisements(struct netdev *netdev,
841 enum netdev_features advertise)
843 return (netdev->netdev_class->set_advertisements
844 ? netdev->netdev_class->set_advertisements(
849 /* If 'netdev' has an assigned IPv4 address, sets '*address' to that address
850 * and '*netmask' to its netmask and returns 0. Otherwise, returns a positive
851 * errno value and sets '*address' to 0 (INADDR_ANY).
853 * The following error values have well-defined meanings:
855 * - EADDRNOTAVAIL: 'netdev' has no assigned IPv4 address.
857 * - EOPNOTSUPP: No IPv4 network stack attached to 'netdev'.
859 * 'address' or 'netmask' or both may be null, in which case the address or
860 * netmask is not reported. */
862 netdev_get_in4(const struct netdev *netdev,
863 struct in_addr *address_, struct in_addr *netmask_)
865 struct in_addr address;
866 struct in_addr netmask;
869 error = (netdev->netdev_class->get_in4
870 ? netdev->netdev_class->get_in4(netdev,
874 address_->s_addr = error ? 0 : address.s_addr;
877 netmask_->s_addr = error ? 0 : netmask.s_addr;
882 /* Assigns 'addr' as 'netdev''s IPv4 address and 'mask' as its netmask. If
883 * 'addr' is INADDR_ANY, 'netdev''s IPv4 address is cleared. Returns a
884 * positive errno value. */
886 netdev_set_in4(struct netdev *netdev, struct in_addr addr, struct in_addr mask)
888 return (netdev->netdev_class->set_in4
889 ? netdev->netdev_class->set_in4(netdev, addr, mask)
893 /* Obtains ad IPv4 address from device name and save the address in
894 * in4. Returns 0 if successful, otherwise a positive errno value.
897 netdev_get_in4_by_name(const char *device_name, struct in_addr *in4)
899 struct netdev *netdev;
902 error = netdev_open(device_name, "system", &netdev);
904 in4->s_addr = htonl(0);
908 error = netdev_get_in4(netdev, in4, NULL);
909 netdev_close(netdev);
913 /* Adds 'router' as a default IP gateway for the TCP/IP stack that corresponds
916 netdev_add_router(struct netdev *netdev, struct in_addr router)
918 COVERAGE_INC(netdev_add_router);
919 return (netdev->netdev_class->add_router
920 ? netdev->netdev_class->add_router(netdev, router)
924 /* Looks up the next hop for 'host' for the TCP/IP stack that corresponds to
925 * 'netdev'. If a route cannot not be determined, sets '*next_hop' to 0,
926 * '*netdev_name' to null, and returns a positive errno value. Otherwise, if a
927 * next hop is found, stores the next hop gateway's address (0 if 'host' is on
928 * a directly connected network) in '*next_hop' and a copy of the name of the
929 * device to reach 'host' in '*netdev_name', and returns 0. The caller is
930 * responsible for freeing '*netdev_name' (by calling free()). */
932 netdev_get_next_hop(const struct netdev *netdev,
933 const struct in_addr *host, struct in_addr *next_hop,
936 int error = (netdev->netdev_class->get_next_hop
937 ? netdev->netdev_class->get_next_hop(
938 host, next_hop, netdev_name)
941 next_hop->s_addr = 0;
947 /* Populates 'smap' with status information.
949 * Populates 'smap' with 'netdev' specific status information. This
950 * information may be used to populate the status column of the Interface table
951 * as defined in ovs-vswitchd.conf.db(5). */
953 netdev_get_status(const struct netdev *netdev, struct smap *smap)
955 return (netdev->netdev_class->get_status
956 ? netdev->netdev_class->get_status(netdev, smap)
960 /* If 'netdev' has an assigned IPv6 address, sets '*in6' to that address and
961 * returns 0. Otherwise, returns a positive errno value and sets '*in6' to
962 * all-zero-bits (in6addr_any).
964 * The following error values have well-defined meanings:
966 * - EADDRNOTAVAIL: 'netdev' has no assigned IPv6 address.
968 * - EOPNOTSUPP: No IPv6 network stack attached to 'netdev'.
970 * 'in6' may be null, in which case the address itself is not reported. */
972 netdev_get_in6(const struct netdev *netdev, struct in6_addr *in6)
974 struct in6_addr dummy;
977 error = (netdev->netdev_class->get_in6
978 ? netdev->netdev_class->get_in6(netdev,
982 memset(in6, 0, sizeof *in6);
987 /* On 'netdev', turns off the flags in 'off' and then turns on the flags in
988 * 'on'. Returns 0 if successful, otherwise a positive errno value. */
990 do_update_flags(struct netdev *netdev, enum netdev_flags off,
991 enum netdev_flags on, enum netdev_flags *old_flagsp,
992 struct netdev_saved_flags **sfp)
993 OVS_EXCLUDED(netdev_mutex)
995 struct netdev_saved_flags *sf = NULL;
996 enum netdev_flags old_flags;
999 error = netdev->netdev_class->update_flags(netdev, off & ~on, on,
1002 VLOG_WARN_RL(&rl, "failed to %s flags for network device %s: %s",
1003 off || on ? "set" : "get", netdev_get_name(netdev),
1004 ovs_strerror(error));
1006 } else if ((off || on) && sfp) {
1007 enum netdev_flags new_flags = (old_flags & ~off) | on;
1008 enum netdev_flags changed_flags = old_flags ^ new_flags;
1009 if (changed_flags) {
1010 ovs_mutex_lock(&netdev_mutex);
1011 *sfp = sf = xmalloc(sizeof *sf);
1012 sf->netdev = netdev;
1013 list_push_front(&netdev->saved_flags_list, &sf->node);
1014 sf->saved_flags = changed_flags;
1015 sf->saved_values = changed_flags & new_flags;
1018 ovs_mutex_unlock(&netdev_mutex);
1023 *old_flagsp = old_flags;
1032 /* Obtains the current flags for 'netdev' and stores them into '*flagsp'.
1033 * Returns 0 if successful, otherwise a positive errno value. On failure,
1034 * stores 0 into '*flagsp'. */
1036 netdev_get_flags(const struct netdev *netdev_, enum netdev_flags *flagsp)
1038 struct netdev *netdev = CONST_CAST(struct netdev *, netdev_);
1039 return do_update_flags(netdev, 0, 0, flagsp, NULL);
1042 /* Sets the flags for 'netdev' to 'flags'.
1043 * Returns 0 if successful, otherwise a positive errno value. */
1045 netdev_set_flags(struct netdev *netdev, enum netdev_flags flags,
1046 struct netdev_saved_flags **sfp)
1048 return do_update_flags(netdev, -1, flags, NULL, sfp);
1051 /* Turns on the specified 'flags' on 'netdev':
1053 * - On success, returns 0. If 'sfp' is nonnull, sets '*sfp' to a newly
1054 * allocated 'struct netdev_saved_flags *' that may be passed to
1055 * netdev_restore_flags() to restore the original values of 'flags' on
1056 * 'netdev' (this will happen automatically at program termination if
1057 * netdev_restore_flags() is never called) , or to NULL if no flags were
1060 * - On failure, returns a positive errno value. If 'sfp' is nonnull, sets
1061 * '*sfp' to NULL. */
1063 netdev_turn_flags_on(struct netdev *netdev, enum netdev_flags flags,
1064 struct netdev_saved_flags **sfp)
1066 return do_update_flags(netdev, 0, flags, NULL, sfp);
1069 /* Turns off the specified 'flags' on 'netdev'. See netdev_turn_flags_on() for
1070 * details of the interface. */
1072 netdev_turn_flags_off(struct netdev *netdev, enum netdev_flags flags,
1073 struct netdev_saved_flags **sfp)
1075 return do_update_flags(netdev, flags, 0, NULL, sfp);
1078 /* Restores the flags that were saved in 'sf', and destroys 'sf'.
1079 * Does nothing if 'sf' is NULL. */
1081 netdev_restore_flags(struct netdev_saved_flags *sf)
1082 OVS_EXCLUDED(netdev_mutex)
1085 struct netdev *netdev = sf->netdev;
1086 enum netdev_flags old_flags;
1088 netdev->netdev_class->update_flags(netdev,
1089 sf->saved_flags & sf->saved_values,
1090 sf->saved_flags & ~sf->saved_values,
1093 ovs_mutex_lock(&netdev_mutex);
1094 list_remove(&sf->node);
1096 netdev_unref(netdev);
1100 /* Looks up the ARP table entry for 'ip' on 'netdev'. If one exists and can be
1101 * successfully retrieved, it stores the corresponding MAC address in 'mac' and
1102 * returns 0. Otherwise, it returns a positive errno value; in particular,
1103 * ENXIO indicates that there is no ARP table entry for 'ip' on 'netdev'. */
1105 netdev_arp_lookup(const struct netdev *netdev,
1106 ovs_be32 ip, uint8_t mac[ETH_ADDR_LEN])
1108 int error = (netdev->netdev_class->arp_lookup
1109 ? netdev->netdev_class->arp_lookup(netdev, ip, mac)
1112 memset(mac, 0, ETH_ADDR_LEN);
1117 /* Returns true if carrier is active (link light is on) on 'netdev'. */
1119 netdev_get_carrier(const struct netdev *netdev)
1122 enum netdev_flags flags;
1125 netdev_get_flags(netdev, &flags);
1126 if (!(flags & NETDEV_UP)) {
1130 if (!netdev->netdev_class->get_carrier) {
1134 error = netdev->netdev_class->get_carrier(netdev, &carrier);
1136 VLOG_DBG("%s: failed to get network device carrier status, assuming "
1137 "down: %s", netdev_get_name(netdev), ovs_strerror(error));
1144 /* Returns the number of times 'netdev''s carrier has changed. */
1146 netdev_get_carrier_resets(const struct netdev *netdev)
1148 return (netdev->netdev_class->get_carrier_resets
1149 ? netdev->netdev_class->get_carrier_resets(netdev)
1153 /* Attempts to force netdev_get_carrier() to poll 'netdev''s MII registers for
1154 * link status instead of checking 'netdev''s carrier. 'netdev''s MII
1155 * registers will be polled once ever 'interval' milliseconds. If 'netdev'
1156 * does not support MII, another method may be used as a fallback. If
1157 * 'interval' is less than or equal to zero, reverts netdev_get_carrier() to
1158 * its normal behavior.
1160 * Returns 0 if successful, otherwise a positive errno value. */
1162 netdev_set_miimon_interval(struct netdev *netdev, long long int interval)
1164 return (netdev->netdev_class->set_miimon_interval
1165 ? netdev->netdev_class->set_miimon_interval(netdev, interval)
1169 /* Retrieves current device stats for 'netdev'. */
1171 netdev_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
1175 COVERAGE_INC(netdev_get_stats);
1176 error = (netdev->netdev_class->get_stats
1177 ? netdev->netdev_class->get_stats(netdev, stats)
1180 memset(stats, 0xff, sizeof *stats);
1185 /* Attempts to change the stats for 'netdev' to those provided in 'stats'.
1186 * Returns 0 if successful, otherwise a positive errno value.
1188 * This will probably fail for most network devices. Some devices might only
1189 * allow setting their stats to 0. */
1191 netdev_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
1193 return (netdev->netdev_class->set_stats
1194 ? netdev->netdev_class->set_stats(netdev, stats)
1198 /* Attempts to set input rate limiting (policing) policy, such that up to
1199 * 'kbits_rate' kbps of traffic is accepted, with a maximum accumulative burst
1200 * size of 'kbits' kb. */
1202 netdev_set_policing(struct netdev *netdev, uint32_t kbits_rate,
1203 uint32_t kbits_burst)
1205 return (netdev->netdev_class->set_policing
1206 ? netdev->netdev_class->set_policing(netdev,
1207 kbits_rate, kbits_burst)
1211 /* Adds to 'types' all of the forms of QoS supported by 'netdev', or leaves it
1212 * empty if 'netdev' does not support QoS. Any names added to 'types' should
1213 * be documented as valid for the "type" column in the "QoS" table in
1214 * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
1216 * Every network device supports disabling QoS with a type of "", but this type
1217 * will not be added to 'types'.
1219 * The caller must initialize 'types' (e.g. with sset_init()) before calling
1220 * this function. The caller is responsible for destroying 'types' (e.g. with
1221 * sset_destroy()) when it is no longer needed.
1223 * Returns 0 if successful, otherwise a positive errno value. */
1225 netdev_get_qos_types(const struct netdev *netdev, struct sset *types)
1227 const struct netdev_class *class = netdev->netdev_class;
1228 return (class->get_qos_types
1229 ? class->get_qos_types(netdev, types)
1233 /* Queries 'netdev' for its capabilities regarding the specified 'type' of QoS,
1234 * which should be "" or one of the types returned by netdev_get_qos_types()
1235 * for 'netdev'. Returns 0 if successful, otherwise a positive errno value.
1236 * On success, initializes 'caps' with the QoS capabilities; on failure, clears
1237 * 'caps' to all zeros. */
1239 netdev_get_qos_capabilities(const struct netdev *netdev, const char *type,
1240 struct netdev_qos_capabilities *caps)
1242 const struct netdev_class *class = netdev->netdev_class;
1245 int retval = (class->get_qos_capabilities
1246 ? class->get_qos_capabilities(netdev, type, caps)
1249 memset(caps, 0, sizeof *caps);
1253 /* Every netdev supports turning off QoS. */
1254 memset(caps, 0, sizeof *caps);
1259 /* Obtains the number of queues supported by 'netdev' for the specified 'type'
1260 * of QoS. Returns 0 if successful, otherwise a positive errno value. Stores
1261 * the number of queues (zero on failure) in '*n_queuesp'.
1263 * This is just a simple wrapper around netdev_get_qos_capabilities(). */
1265 netdev_get_n_queues(const struct netdev *netdev,
1266 const char *type, unsigned int *n_queuesp)
1268 struct netdev_qos_capabilities caps;
1271 retval = netdev_get_qos_capabilities(netdev, type, &caps);
1272 *n_queuesp = caps.n_queues;
1276 /* Queries 'netdev' about its currently configured form of QoS. If successful,
1277 * stores the name of the current form of QoS into '*typep', stores any details
1278 * of configuration as string key-value pairs in 'details', and returns 0. On
1279 * failure, sets '*typep' to NULL and returns a positive errno value.
1281 * A '*typep' of "" indicates that QoS is currently disabled on 'netdev'.
1283 * The caller must initialize 'details' as an empty smap (e.g. with
1284 * smap_init()) before calling this function. The caller must free 'details'
1285 * when it is no longer needed (e.g. with smap_destroy()).
1287 * The caller must not modify or free '*typep'.
1289 * '*typep' will be one of the types returned by netdev_get_qos_types() for
1290 * 'netdev'. The contents of 'details' should be documented as valid for
1291 * '*typep' in the "other_config" column in the "QoS" table in
1292 * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)). */
1294 netdev_get_qos(const struct netdev *netdev,
1295 const char **typep, struct smap *details)
1297 const struct netdev_class *class = netdev->netdev_class;
1300 if (class->get_qos) {
1301 retval = class->get_qos(netdev, typep, details);
1304 smap_clear(details);
1308 /* 'netdev' doesn't support QoS, so report that QoS is disabled. */
1314 /* Attempts to reconfigure QoS on 'netdev', changing the form of QoS to 'type'
1315 * with details of configuration from 'details'. Returns 0 if successful,
1316 * otherwise a positive errno value. On error, the previous QoS configuration
1319 * When this function changes the type of QoS (not just 'details'), this also
1320 * resets all queue configuration for 'netdev' to their defaults (which depend
1321 * on the specific type of QoS). Otherwise, the queue configuration for
1322 * 'netdev' is unchanged.
1324 * 'type' should be "" (to disable QoS) or one of the types returned by
1325 * netdev_get_qos_types() for 'netdev'. The contents of 'details' should be
1326 * documented as valid for the given 'type' in the "other_config" column in the
1327 * "QoS" table in vswitchd/vswitch.xml (which is built as
1328 * ovs-vswitchd.conf.db(8)).
1330 * NULL may be specified for 'details' if there are no configuration
1333 netdev_set_qos(struct netdev *netdev,
1334 const char *type, const struct smap *details)
1336 const struct netdev_class *class = netdev->netdev_class;
1342 if (class->set_qos) {
1344 static const struct smap empty = SMAP_INITIALIZER(&empty);
1347 return class->set_qos(netdev, type, details);
1349 return *type ? EOPNOTSUPP : 0;
1353 /* Queries 'netdev' for information about the queue numbered 'queue_id'. If
1354 * successful, adds that information as string key-value pairs to 'details'.
1355 * Returns 0 if successful, otherwise a positive errno value.
1357 * 'queue_id' must be less than the number of queues supported by 'netdev' for
1358 * the current form of QoS (e.g. as returned by netdev_get_n_queues(netdev)).
1360 * The returned contents of 'details' should be documented as valid for the
1361 * given 'type' in the "other_config" column in the "Queue" table in
1362 * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
1364 * The caller must initialize 'details' (e.g. with smap_init()) before calling
1365 * this function. The caller must free 'details' when it is no longer needed
1366 * (e.g. with smap_destroy()). */
1368 netdev_get_queue(const struct netdev *netdev,
1369 unsigned int queue_id, struct smap *details)
1371 const struct netdev_class *class = netdev->netdev_class;
1374 retval = (class->get_queue
1375 ? class->get_queue(netdev, queue_id, details)
1378 smap_clear(details);
1383 /* Configures the queue numbered 'queue_id' on 'netdev' with the key-value
1384 * string pairs in 'details'. The contents of 'details' should be documented
1385 * as valid for the given 'type' in the "other_config" column in the "Queue"
1386 * table in vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
1387 * Returns 0 if successful, otherwise a positive errno value. On failure, the
1388 * given queue's configuration should be unmodified.
1390 * 'queue_id' must be less than the number of queues supported by 'netdev' for
1391 * the current form of QoS (e.g. as returned by netdev_get_n_queues(netdev)).
1393 * This function does not modify 'details', and the caller retains ownership of
1396 netdev_set_queue(struct netdev *netdev,
1397 unsigned int queue_id, const struct smap *details)
1399 const struct netdev_class *class = netdev->netdev_class;
1400 return (class->set_queue
1401 ? class->set_queue(netdev, queue_id, details)
1405 /* Attempts to delete the queue numbered 'queue_id' from 'netdev'. Some kinds
1406 * of QoS may have a fixed set of queues, in which case attempts to delete them
1407 * will fail with EOPNOTSUPP.
1409 * Returns 0 if successful, otherwise a positive errno value. On failure, the
1410 * given queue will be unmodified.
1412 * 'queue_id' must be less than the number of queues supported by 'netdev' for
1413 * the current form of QoS (e.g. as returned by
1414 * netdev_get_n_queues(netdev)). */
1416 netdev_delete_queue(struct netdev *netdev, unsigned int queue_id)
1418 const struct netdev_class *class = netdev->netdev_class;
1419 return (class->delete_queue
1420 ? class->delete_queue(netdev, queue_id)
1424 /* Obtains statistics about 'queue_id' on 'netdev'. On success, returns 0 and
1425 * fills 'stats' with the queue's statistics; individual members of 'stats' may
1426 * be set to all-1-bits if the statistic is unavailable. On failure, returns a
1427 * positive errno value and fills 'stats' with values indicating unsupported
1430 netdev_get_queue_stats(const struct netdev *netdev, unsigned int queue_id,
1431 struct netdev_queue_stats *stats)
1433 const struct netdev_class *class = netdev->netdev_class;
1436 retval = (class->get_queue_stats
1437 ? class->get_queue_stats(netdev, queue_id, stats)
1440 stats->tx_bytes = UINT64_MAX;
1441 stats->tx_packets = UINT64_MAX;
1442 stats->tx_errors = UINT64_MAX;
1443 stats->created = LLONG_MIN;
1448 /* Initializes 'dump' to begin dumping the queues in a netdev.
1450 * This function provides no status indication. An error status for the entire
1451 * dump operation is provided when it is completed by calling
1452 * netdev_queue_dump_done().
1455 netdev_queue_dump_start(struct netdev_queue_dump *dump,
1456 const struct netdev *netdev)
1458 dump->netdev = netdev_ref(netdev);
1459 if (netdev->netdev_class->queue_dump_start) {
1460 dump->error = netdev->netdev_class->queue_dump_start(netdev,
1463 dump->error = EOPNOTSUPP;
1467 /* Attempts to retrieve another queue from 'dump', which must have been
1468 * initialized with netdev_queue_dump_start(). On success, stores a new queue
1469 * ID into '*queue_id', fills 'details' with configuration details for the
1470 * queue, and returns true. On failure, returns false.
1472 * Queues are not necessarily dumped in increasing order of queue ID (or any
1473 * other predictable order).
1475 * Failure might indicate an actual error or merely that the last queue has
1476 * been dumped. An error status for the entire dump operation is provided when
1477 * it is completed by calling netdev_queue_dump_done().
1479 * The returned contents of 'details' should be documented as valid for the
1480 * given 'type' in the "other_config" column in the "Queue" table in
1481 * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
1483 * The caller must initialize 'details' (e.g. with smap_init()) before calling
1484 * this function. This function will clear and replace its contents. The
1485 * caller must free 'details' when it is no longer needed (e.g. with
1486 * smap_destroy()). */
1488 netdev_queue_dump_next(struct netdev_queue_dump *dump,
1489 unsigned int *queue_id, struct smap *details)
1491 const struct netdev *netdev = dump->netdev;
1497 dump->error = netdev->netdev_class->queue_dump_next(netdev, dump->state,
1501 netdev->netdev_class->queue_dump_done(netdev, dump->state);
1507 /* Completes queue table dump operation 'dump', which must have been
1508 * initialized with netdev_queue_dump_start(). Returns 0 if the dump operation
1509 * was error-free, otherwise a positive errno value describing the problem. */
1511 netdev_queue_dump_done(struct netdev_queue_dump *dump)
1513 const struct netdev *netdev = dump->netdev;
1514 if (!dump->error && netdev->netdev_class->queue_dump_done) {
1515 dump->error = netdev->netdev_class->queue_dump_done(netdev,
1518 netdev_close(dump->netdev);
1519 return dump->error == EOF ? 0 : dump->error;
1522 /* Iterates over all of 'netdev''s queues, calling 'cb' with the queue's ID,
1523 * its statistics, and the 'aux' specified by the caller. The order of
1524 * iteration is unspecified, but (when successful) each queue is visited
1527 * Calling this function may be more efficient than calling
1528 * netdev_get_queue_stats() for every queue.
1530 * 'cb' must not modify or free the statistics passed in.
1532 * Returns 0 if successful, otherwise a positive errno value. On error, some
1533 * configured queues may not have been included in the iteration. */
1535 netdev_dump_queue_stats(const struct netdev *netdev,
1536 netdev_dump_queue_stats_cb *cb, void *aux)
1538 const struct netdev_class *class = netdev->netdev_class;
1539 return (class->dump_queue_stats
1540 ? class->dump_queue_stats(netdev, cb, aux)
1545 /* Returns the class type of 'netdev'.
1547 * The caller must not free the returned value. */
1549 netdev_get_type(const struct netdev *netdev)
1551 return netdev->netdev_class->type;
1554 /* Returns the class associated with 'netdev'. */
1555 const struct netdev_class *
1556 netdev_get_class(const struct netdev *netdev)
1558 return netdev->netdev_class;
1561 /* Returns the netdev with 'name' or NULL if there is none.
1563 * The caller must free the returned netdev with netdev_close(). */
1565 netdev_from_name(const char *name)
1566 OVS_EXCLUDED(netdev_mutex)
1568 struct netdev *netdev;
1570 ovs_mutex_lock(&netdev_mutex);
1571 netdev = shash_find_data(&netdev_shash, name);
1575 ovs_mutex_unlock(&netdev_mutex);
1580 /* Fills 'device_list' with devices that match 'netdev_class'.
1582 * The caller is responsible for initializing and destroying 'device_list' and
1583 * must close each device on the list. */
1585 netdev_get_devices(const struct netdev_class *netdev_class,
1586 struct shash *device_list)
1587 OVS_EXCLUDED(netdev_mutex)
1589 struct shash_node *node;
1591 ovs_mutex_lock(&netdev_mutex);
1592 SHASH_FOR_EACH (node, &netdev_shash) {
1593 struct netdev *dev = node->data;
1595 if (dev->netdev_class == netdev_class) {
1597 shash_add(device_list, node->name, node->data);
1600 ovs_mutex_unlock(&netdev_mutex);
1604 netdev_get_type_from_name(const char *name)
1606 struct netdev *dev = netdev_from_name(name);
1607 const char *type = dev ? netdev_get_type(dev) : NULL;
1613 netdev_rxq_get_netdev(const struct netdev_rxq *rx)
1615 ovs_assert(rx->netdev->ref_cnt > 0);
1620 netdev_rxq_get_name(const struct netdev_rxq *rx)
1622 return netdev_get_name(netdev_rxq_get_netdev(rx));
1626 restore_all_flags(void *aux OVS_UNUSED)
1628 struct shash_node *node;
1630 SHASH_FOR_EACH (node, &netdev_shash) {
1631 struct netdev *netdev = node->data;
1632 const struct netdev_saved_flags *sf;
1633 enum netdev_flags saved_values;
1634 enum netdev_flags saved_flags;
1636 saved_values = saved_flags = 0;
1637 LIST_FOR_EACH (sf, node, &netdev->saved_flags_list) {
1638 saved_flags |= sf->saved_flags;
1639 saved_values &= ~sf->saved_flags;
1640 saved_values |= sf->saved_flags & sf->saved_values;
1643 enum netdev_flags old_flags;
1645 netdev->netdev_class->update_flags(netdev,
1646 saved_flags & saved_values,
1647 saved_flags & ~saved_values,