2 * Copyright (c) 2010 Nicira Networks.
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 apatched 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.
21 #include <sys/ioctl.h>
23 #include "netdev-provider.h"
24 #include "netdev-vport.h"
25 #include "openflow/openflow.h"
26 #include "openvswitch/datapath-protocol.h"
28 #include "socket-util.h"
31 VLOG_DEFINE_THIS_MODULE(netdev_patch)
33 struct netdev_dev_patch {
34 struct netdev_dev netdev_dev;
41 static struct netdev_dev_patch *
42 netdev_dev_patch_cast(const struct netdev_dev *netdev_dev)
44 netdev_dev_assert_class(netdev_dev, &netdev_patch_class);
45 return CONTAINER_OF(netdev_dev, struct netdev_dev_patch, netdev_dev);
48 static struct netdev_patch *
49 netdev_patch_cast(const struct netdev *netdev)
51 netdev_assert_class(netdev, &netdev_patch_class);
52 return CONTAINER_OF(netdev, struct netdev_patch, netdev);
56 parse_config(const char *name, const struct shash *args,
61 peer = shash_find_data(args, "peer");
63 VLOG_WARN("%s: patch type requires valid 'peer' argument", name);
67 if (shash_count(args) > 1) {
68 VLOG_WARN("%s: patch type takes only a 'peer' argument", name);
72 if (strlen(peer) >= IFNAMSIZ) {
73 VLOG_WARN("%s: patch 'peer' arg too long", name);
77 if (!strcmp(name, peer)) {
78 VLOG_WARN("%s: patch peer must not be self", name);
88 netdev_patch_create(const char *name, const char *type OVS_UNUSED,
89 const struct shash *args, struct netdev_dev **netdev_devp)
92 struct odp_vport_add ova;
94 struct netdev_dev_patch *netdev_dev;
96 err = parse_config(name, args, &peer);
101 ovs_strlcpy(ova.port_type, "patch", sizeof ova.port_type);
102 ovs_strlcpy(ova.devname, name, sizeof ova.devname);
103 ova.config = (char *)peer;
105 err = netdev_vport_do_ioctl(ODP_VPORT_ADD, &ova);
107 VLOG_WARN("%s: destroying existing device", name);
109 err = netdev_vport_do_ioctl(ODP_VPORT_DEL, ova.devname);
114 err = netdev_vport_do_ioctl(ODP_VPORT_ADD, &ova);
121 netdev_dev = xmalloc(sizeof *netdev_dev);
122 netdev_dev_init(&netdev_dev->netdev_dev, name, &netdev_patch_class);
124 *netdev_devp = &netdev_dev->netdev_dev;
129 netdev_patch_reconfigure(struct netdev_dev *netdev_dev_, const struct shash *args)
131 const char *name = netdev_dev_get_name(netdev_dev_);
132 struct odp_vport_mod ovm;
136 err = parse_config(name, args, &peer);
141 ovs_strlcpy(ovm.devname, name, sizeof ovm.devname);
142 ovm.config = (char *)peer;
144 return netdev_vport_do_ioctl(ODP_VPORT_MOD, &ovm);
148 netdev_patch_destroy(struct netdev_dev *netdev_dev_)
150 struct netdev_dev_patch *netdev_dev = netdev_dev_patch_cast(netdev_dev_);
152 netdev_vport_do_ioctl(ODP_VPORT_DEL, (char *)netdev_dev_get_name(netdev_dev_));
157 netdev_patch_open(struct netdev_dev *netdev_dev_, int ethertype OVS_UNUSED,
158 struct netdev **netdevp)
160 struct netdev_patch *netdev;
162 netdev = xmalloc(sizeof *netdev);
163 netdev_init(&netdev->netdev, netdev_dev_);
165 *netdevp = &netdev->netdev;
170 netdev_patch_close(struct netdev *netdev_)
172 struct netdev_patch *netdev = netdev_patch_cast(netdev_);
176 const struct netdev_class netdev_patch_class = {
184 netdev_patch_destroy,
185 netdev_patch_reconfigure,
190 NULL, /* enumerate */
193 NULL, /* recv_wait */
197 NULL, /* send_wait */
199 netdev_vport_set_etheraddr,
200 netdev_vport_get_etheraddr,
201 netdev_vport_get_mtu,
202 NULL, /* get_ifindex */
203 netdev_vport_get_carrier,
204 netdev_vport_get_stats,
205 netdev_vport_set_stats,
207 NULL, /* get_features */
208 NULL, /* set_advertisements */
209 NULL, /* get_vlan_vid */
211 NULL, /* set_policing */
212 NULL, /* get_qos_types */
213 NULL, /* get_qos_capabilities */
216 NULL, /* get_queue */
217 NULL, /* set_queue */
218 NULL, /* delete_queue */
219 NULL, /* get_queue_stats */
220 NULL, /* dump_queues */
221 NULL, /* dump_queue_stats */
226 NULL, /* add_router */
227 NULL, /* get_next_hop */
228 NULL, /* arp_lookup */
230 netdev_vport_update_flags,
232 netdev_vport_poll_add,
233 netdev_vport_poll_remove,