105
105
* the Netlink version of the command, even if actions_len is zero. */
106
106
const struct nlattr *key; /* OVS_FLOW_ATTR_KEY. */
108
const struct nlattr *mask; /* OVS_FLOW_ATTR_MASK. */
108
110
const struct nlattr *actions; /* OVS_FLOW_ATTR_ACTIONS. */
109
111
size_t actions_len;
110
112
const struct ovs_flow_stats *stats; /* OVS_FLOW_ATTR_STATS. */
146
149
int event_offset; /* Offset into 'epoll_events'. */
148
151
/* Change notification. */
149
struct sset changed_ports; /* Ports that have changed. */
150
struct nln_notifier *port_notifier;
152
struct nl_sock *port_notifier; /* vport multicast group subscriber. */
154
155
static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(9999, 5);
156
/* Generic Netlink family numbers for OVS. */
157
/* Generic Netlink family numbers for OVS.
159
* Initialized by dpif_linux_init(). */
157
160
static int ovs_datapath_family;
158
161
static int ovs_vport_family;
159
162
static int ovs_flow_family;
160
163
static int ovs_packet_family;
162
/* Generic Netlink socket. */
163
static struct nl_sock *genl_sock;
164
static struct nln *nln = NULL;
165
/* Generic Netlink multicast groups for OVS.
167
* Initialized by dpif_linux_init(). */
168
static unsigned int ovs_vport_mcgroup;
166
170
static int dpif_linux_init(void);
167
static void open_dpif(const struct dpif_linux_dp *, struct dpif **);
168
static bool dpif_linux_nln_parse(struct ofpbuf *, void *);
169
static void dpif_linux_port_changed(const void *vport, void *dpif);
170
static uint32_t dpif_linux_port_get_pid(const struct dpif *, uint32_t port_no);
171
static int open_dpif(const struct dpif_linux_dp *, struct dpif **);
172
static uint32_t dpif_linux_port_get_pid(const struct dpif *,
172
175
static void dpif_linux_vport_to_ofpbuf(const struct dpif_linux_vport *,
173
176
struct ofpbuf *);
236
open_dpif(&dp, dpifp);
239
error = open_dpif(&dp, dpifp);
237
240
ofpbuf_delete(buf);
242
245
open_dpif(const struct dpif_linux_dp *dp, struct dpif **dpifp)
244
247
struct dpif_linux *dpif;
246
249
dpif = xzalloc(sizeof *dpif);
247
dpif->port_notifier = nln_notifier_create(nln, dpif_linux_port_changed,
250
dpif->port_notifier = NULL;
251
ovs_mutex_init(&dpif->upcall_lock, PTHREAD_MUTEX_DEFAULT);
249
252
dpif->epoll_fd = -1;
251
254
dpif_init(&dpif->dpif, &dpif_linux_class, dp->name,
252
255
dp->dp_ifindex, dp->dp_ifindex);
254
257
dpif->dp_ifindex = dp->dp_ifindex;
255
sset_init(&dpif->changed_ports);
256
258
*dpifp = &dpif->dpif;
260
264
destroy_channels(struct dpif_linux *dpif)
264
268
if (dpif->epoll_fd < 0) {
281
epoll_ctl(dpif->epoll_fd, EPOLL_CTL_DEL, nl_sock_fd(ch->sock), NULL);
277
283
/* Turn off upcalls. */
278
284
dpif_linux_vport_init(&vport_request);
279
285
vport_request.cmd = OVS_VPORT_CMD_SET;
280
286
vport_request.dp_ifindex = dpif->dp_ifindex;
281
vport_request.port_no = i;
287
vport_request.port_no = u32_to_odp(i);
282
288
vport_request.upcall_pid = &upcall_pid;
283
289
dpif_linux_vport_transact(&vport_request, NULL, NULL);
293
299
dpif->epoll_events = NULL;
294
300
dpif->n_events = dpif->event_offset = 0;
296
close(dpif->epoll_fd);
302
/* Don't close dpif->epoll_fd since that would cause other threads that
303
* call dpif_recv_wait(dpif) to wait on an arbitrary fd or a closed fd. */
301
add_channel(struct dpif_linux *dpif, uint32_t port_no, struct nl_sock *sock)
307
add_channel(struct dpif_linux *dpif, odp_port_t port_no, struct nl_sock *sock)
303
309
struct epoll_event event;
310
uint32_t port_idx = odp_to_u32(port_no);
305
312
if (dpif->epoll_fd < 0) {
309
316
/* We assume that the datapath densely chooses port numbers, which
310
317
* can therefore be used as an index into an array of channels. */
311
if (port_no >= dpif->uc_array_size) {
312
int new_size = port_no + 1;
318
if (port_idx >= dpif->uc_array_size) {
319
uint32_t new_size = port_idx + 1;
315
if (new_size > 65535) {
322
if (new_size > MAX_PORTS) {
316
323
VLOG_WARN_RL(&error_rl, "%s: datapath port %"PRIu32" too big",
317
324
dpif_name(&dpif->dpif), port_no);
332
339
memset(&event, 0, sizeof event);
333
340
event.events = EPOLLIN;
334
event.data.u32 = port_no;
341
event.data.u32 = port_idx;
335
342
if (epoll_ctl(dpif->epoll_fd, EPOLL_CTL_ADD, nl_sock_fd(sock),
340
nl_sock_destroy(dpif->channels[port_no].sock);
341
dpif->channels[port_no].sock = sock;
342
dpif->channels[port_no].last_poll = LLONG_MIN;
347
nl_sock_destroy(dpif->channels[port_idx].sock);
348
dpif->channels[port_idx].sock = sock;
349
dpif->channels[port_idx].last_poll = LLONG_MIN;
348
del_channel(struct dpif_linux *dpif, uint32_t port_no)
355
del_channel(struct dpif_linux *dpif, odp_port_t port_no)
350
357
struct dpif_channel *ch;
358
uint32_t port_idx = odp_to_u32(port_no);
352
if (dpif->epoll_fd < 0 || port_no >= dpif->uc_array_size) {
360
if (dpif->epoll_fd < 0 || port_idx >= dpif->uc_array_size) {
356
ch = &dpif->channels[port_no];
364
ch = &dpif->channels[port_idx];
371
379
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
373
nln_notifier_destroy(dpif->port_notifier);
381
nl_sock_destroy(dpif->port_notifier);
374
382
destroy_channels(dpif);
375
sset_destroy(&dpif->changed_ports);
383
if (dpif->epoll_fd >= 0) {
384
close(dpif->epoll_fd);
386
ovs_mutex_destroy(&dpif->upcall_lock);
388
399
return dpif_linux_dp_transact(&dp, NULL, NULL);
392
dpif_linux_run(struct dpif *dpif_ OVS_UNUSED)
400
dpif_linux_wait(struct dpif *dpif OVS_UNUSED)
408
403
dpif_linux_get_stats(const struct dpif *dpif_, struct dpif_dp_stats *stats)
468
466
return OVS_VPORT_TYPE_GRE;
469
467
} else if (!strcmp(type, "vxlan")) {
470
468
return OVS_VPORT_TYPE_VXLAN;
469
} else if (!strcmp(type, "lisp")) {
470
return OVS_VPORT_TYPE_LISP;
472
472
return OVS_VPORT_TYPE_UNSPEC;
477
dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
477
dpif_linux_port_add__(struct dpif *dpif_, struct netdev *netdev,
478
odp_port_t *port_nop)
480
480
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
481
481
const struct netdev_tunnel_config *tnl_cfg;
482
const char *name = netdev_vport_get_dpif_port(netdev);
482
char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
483
const char *name = netdev_vport_get_dpif_port(netdev,
484
namebuf, sizeof namebuf);
483
485
const char *type = netdev_get_type(netdev);
484
486
struct dpif_linux_vport request, reply;
485
487
struct nl_sock *sock = NULL;
532
534
VLOG_DBG("%s: assigning port %"PRIu32" to netlink pid %"PRIu32,
533
535
dpif_name(dpif_), reply.port_no, upcall_pid);
535
if (error == EBUSY && *port_nop != UINT32_MAX) {
537
if (error == EBUSY && *port_nop != ODPP_NONE) {
536
538
VLOG_INFO("%s: requested port %"PRIu32" is in use",
537
539
dpif_name(dpif_), *port_nop);
567
dpif_linux_port_del(struct dpif *dpif_, uint32_t port_no)
569
dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
570
odp_port_t *port_nop)
572
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
575
ovs_mutex_lock(&dpif->upcall_lock);
576
error = dpif_linux_port_add__(dpif_, netdev, port_nop);
577
ovs_mutex_unlock(&dpif->upcall_lock);
583
dpif_linux_port_del__(struct dpif *dpif_, odp_port_t port_no)
569
585
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
570
586
struct dpif_linux_vport vport;
585
dpif_linux_port_query__(const struct dpif *dpif, uint32_t port_no,
601
dpif_linux_port_del(struct dpif *dpif_, odp_port_t port_no)
603
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
606
ovs_mutex_lock(&dpif->upcall_lock);
607
error = dpif_linux_port_del__(dpif_, port_no);
608
ovs_mutex_unlock(&dpif->upcall_lock);
614
dpif_linux_port_query__(const struct dpif *dpif, odp_port_t port_no,
586
615
const char *port_name, struct dpif_port *dpif_port)
588
617
struct dpif_linux_vport request;
616
dpif_linux_port_query_by_number(const struct dpif *dpif, uint32_t port_no,
645
dpif_linux_port_query_by_number(const struct dpif *dpif, odp_port_t port_no,
617
646
struct dpif_port *dpif_port)
619
648
return dpif_linux_port_query__(dpif, port_no, NULL, dpif_port);
626
655
return dpif_linux_port_query__(dpif, 0, devname, dpif_port);
630
659
dpif_linux_get_max_ports(const struct dpif *dpif OVS_UNUSED)
661
return u32_to_odp(MAX_PORTS);
636
dpif_linux_port_get_pid(const struct dpif *dpif_, uint32_t port_no)
665
dpif_linux_port_get_pid(const struct dpif *dpif_, odp_port_t port_no)
638
667
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
668
uint32_t port_idx = odp_to_u32(port_no);
640
if (dpif->epoll_fd < 0) {
643
/* The UINT32_MAX "reserved" port number uses the "ovs-system"'s
671
ovs_mutex_lock(&dpif->upcall_lock);
672
if (dpif->epoll_fd >= 0) {
673
/* The ODPP_NONE "reserved" port number uses the "ovs-system"'s
644
674
* channel, since it is not heavily loaded. */
645
int idx = (port_no >= dpif->uc_array_size) ? 0 : port_no;
646
return nl_sock_pid(dpif->channels[idx].sock);
675
uint32_t idx = port_idx >= dpif->uc_array_size ? 0 : port_idx;
676
pid = nl_sock_pid(dpif->channels[idx].sock);
678
ovs_mutex_unlock(&dpif->upcall_lock);
651
684
dpif_linux_flow_flush(struct dpif *dpif_)
653
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
686
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
654
687
struct dpif_linux_flow flow;
656
689
dpif_linux_flow_init(&flow);
667
700
dpif_linux_port_dump_start(const struct dpif *dpif_, void **statep)
669
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
702
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
670
703
struct dpif_linux_port_state *state;
671
704
struct dpif_linux_vport request;
672
705
struct ofpbuf *buf;
680
713
buf = ofpbuf_new(1024);
681
714
dpif_linux_vport_to_ofpbuf(&request, buf);
682
nl_dump_start(&state->dump, genl_sock, buf);
715
nl_dump_start(&state->dump, NETLINK_GENERIC, buf);
683
716
ofpbuf_delete(buf);
725
758
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
727
if (dpif->change_error) {
728
dpif->change_error = false;
729
sset_clear(&dpif->changed_ports);
731
} else if (!sset_is_empty(&dpif->changed_ports)) {
732
*devnamep = sset_pop(&dpif->changed_ports);
760
/* Lazily create the Netlink socket to listen for notifications. */
761
if (!dpif->port_notifier) {
762
struct nl_sock *sock;
765
error = nl_sock_create(NETLINK_GENERIC, &sock);
770
error = nl_sock_join_mcgroup(sock, ovs_vport_mcgroup);
772
nl_sock_destroy(sock);
775
dpif->port_notifier = sock;
777
/* We have no idea of the current state so report that everything
783
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
784
uint64_t buf_stub[4096 / 8];
788
ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub);
789
error = nl_sock_recv(dpif->port_notifier, &buf, false);
791
struct dpif_linux_vport vport;
793
error = dpif_linux_vport_from_ofpbuf(&vport, &buf);
795
if (vport.dp_ifindex == dpif->dp_ifindex
796
&& (vport.cmd == OVS_VPORT_CMD_NEW
797
|| vport.cmd == OVS_VPORT_CMD_DEL
798
|| vport.cmd == OVS_VPORT_CMD_SET)) {
799
VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8,
800
dpif->dpif.full_name, vport.name, vport.cmd);
801
*devnamep = xstrdup(vport.name);
807
} else if (error == EAGAIN) {
811
VLOG_WARN_RL(&rl, "error reading or parsing netlink (%s)",
812
ovs_strerror(error));
813
nl_sock_drain(dpif->port_notifier);
740
819
dpif_linux_port_poll_wait(const struct dpif *dpif_)
742
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
743
if (!sset_is_empty(&dpif->changed_ports) || dpif->change_error) {
821
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
823
if (dpif->port_notifier) {
824
nl_sock_wait(dpif->port_notifier, POLLIN);
744
826
poll_immediate_wake();
750
832
const struct nlattr *key, size_t key_len,
751
833
struct dpif_linux_flow *reply, struct ofpbuf **bufp)
753
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
835
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
754
836
struct dpif_linux_flow request;
756
838
dpif_linux_flow_init(&request);
790
872
dpif_linux_init_flow_put(struct dpif *dpif_, const struct dpif_flow_put *put,
791
873
struct dpif_linux_flow *request)
793
static struct nlattr dummy_action;
875
static const struct nlattr dummy_action;
795
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
877
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
797
879
dpif_linux_flow_init(request);
798
880
request->cmd = (put->flags & DPIF_FP_CREATE
800
882
request->dp_ifindex = dpif->dp_ifindex;
801
883
request->key = put->key;
802
884
request->key_len = put->key_len;
885
request->mask = put->mask;
886
request->mask_len = put->mask_len;
803
887
/* Ensure that OVS_FLOW_ATTR_ACTIONS will always be included. */
804
request->actions = put->actions ? put->actions : &dummy_action;
888
request->actions = (put->actions
890
: CONST_CAST(struct nlattr *, &dummy_action));
805
891
request->actions_len = put->actions_len;
806
892
if (put->flags & DPIF_FP_ZERO_STATS) {
807
893
request->clear = true;
831
917
dpif_linux_init_flow_del(struct dpif *dpif_, const struct dpif_flow_del *del,
832
918
struct dpif_linux_flow *request)
834
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
920
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
836
922
dpif_linux_flow_init(request);
837
923
request->cmd = OVS_FLOW_CMD_DEL;
869
955
dpif_linux_flow_dump_start(const struct dpif *dpif_, void **statep)
871
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
957
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
872
958
struct dpif_linux_flow_state *state;
873
959
struct dpif_linux_flow request;
874
960
struct ofpbuf *buf;
882
968
buf = ofpbuf_new(1024);
883
969
dpif_linux_flow_to_ofpbuf(&request, buf);
884
nl_dump_start(&state->dump, genl_sock, buf);
970
nl_dump_start(&state->dump, NETLINK_GENERIC, buf);
885
971
ofpbuf_delete(buf);
887
973
state->buf = NULL;
893
979
dpif_linux_flow_dump_next(const struct dpif *dpif_ OVS_UNUSED, void *state_,
894
980
const struct nlattr **key, size_t *key_len,
981
const struct nlattr **mask, size_t *mask_len,
895
982
const struct nlattr **actions, size_t *actions_len,
896
983
const struct dpif_flow_stats **stats)
983
1075
ofpbuf_use_stub(&request, request_stub, sizeof request_stub);
984
1076
dpif_linux_encode_execute(dp_ifindex, execute, &request);
985
error = nl_sock_transact(genl_sock, &request, NULL);
1077
error = nl_transact(NETLINK_GENERIC, &request, NULL);
986
1078
ofpbuf_uninit(&request);
992
1084
dpif_linux_execute(struct dpif *dpif_, const struct dpif_execute *execute)
994
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1086
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
996
1088
return dpif_linux_execute__(dpif->dp_ifindex, execute);
1002
1094
dpif_linux_operate__(struct dpif *dpif_, struct dpif_op **ops, size_t n_ops)
1004
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1096
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1006
1098
struct op_auxdata {
1007
1099
struct nl_transaction txn;
1067
1159
for (i = 0; i < n_ops; i++) {
1068
1160
txnsp[i] = &auxes[i].txn;
1070
nl_sock_transact_multiple(genl_sock, txnsp, n_ops);
1162
nl_transact_multiple(NETLINK_GENERIC, txnsp, n_ops);
1072
1164
for (i = 0; i < n_ops; i++) {
1073
1165
struct op_auxdata *aux = &auxes[i];
1155
1247
struct dpif_port_dump port_dump;
1156
1248
struct dpif_port port;
1158
dpif->epoll_fd = epoll_create(10);
1159
1250
if (dpif->epoll_fd < 0) {
1251
dpif->epoll_fd = epoll_create(10);
1252
if (dpif->epoll_fd < 0) {
1163
1257
DPIF_PORT_FOR_EACH (&port, &port_dump, &dpif->dpif) {
1187
1281
VLOG_WARN_RL(&error_rl,
1188
1282
"%s: failed to set upcall pid on port: %s",
1189
dpif_name(&dpif->dpif), strerror(error));
1283
dpif_name(&dpif->dpif), ovs_strerror(error));
1190
1284
nl_sock_destroy(sock);
1192
1286
if (error == ENODEV || error == ENOENT) {
1308
dpif_linux_recv_set(struct dpif *dpif_, bool enable)
1310
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1313
ovs_mutex_lock(&dpif->upcall_lock);
1314
error = dpif_linux_recv_set__(dpif_, enable);
1315
ovs_mutex_unlock(&dpif->upcall_lock);
1214
1321
dpif_linux_queue_to_priority(const struct dpif *dpif OVS_UNUSED,
1215
1322
uint32_t queue_id, uint32_t *priority)
1233
1340
[OVS_PACKET_ATTR_KEY] = { .type = NL_A_NESTED },
1235
1342
/* OVS_PACKET_CMD_ACTION only. */
1236
[OVS_PACKET_ATTR_USERDATA] = { .type = NL_A_U64, .optional = true },
1343
[OVS_PACKET_ATTR_USERDATA] = { .type = NL_A_UNSPEC, .optional = true },
1239
1346
struct ovs_header *ovs_header;
1271
1378
upcall->key = CONST_CAST(struct nlattr *,
1272
1379
nl_attr_get(a[OVS_PACKET_ATTR_KEY]));
1273
1380
upcall->key_len = nl_attr_get_size(a[OVS_PACKET_ATTR_KEY]);
1274
upcall->userdata = (a[OVS_PACKET_ATTR_USERDATA]
1275
? nl_attr_get_u64(a[OVS_PACKET_ATTR_USERDATA])
1381
upcall->userdata = a[OVS_PACKET_ATTR_USERDATA];
1277
1382
*dp_ifindex = ovs_header->dp_ifindex;
1283
dpif_linux_recv(struct dpif *dpif_, struct dpif_upcall *upcall,
1388
dpif_linux_recv__(struct dpif *dpif_, struct dpif_upcall *upcall,
1286
1391
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1287
1392
int read_tries = 0;
1301
1406
} while (retval < 0 && errno == EINTR);
1302
1407
if (retval < 0) {
1303
1408
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
1304
VLOG_WARN_RL(&rl, "epoll_wait failed (%s)", strerror(errno));
1409
VLOG_WARN_RL(&rl, "epoll_wait failed (%s)", ovs_strerror(errno));
1305
1410
} else if (retval > 0) {
1306
1411
dpif->n_events = retval;
1460
dpif_linux_recv(struct dpif *dpif_, struct dpif_upcall *upcall,
1463
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1466
ovs_mutex_lock(&dpif->upcall_lock);
1467
error = dpif_linux_recv__(dpif_, upcall, buf);
1468
ovs_mutex_unlock(&dpif->upcall_lock);
1355
1474
dpif_linux_recv_wait(struct dpif *dpif_)
1357
1476
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1359
if (dpif->epoll_fd < 0) {
1478
ovs_mutex_lock(&dpif->upcall_lock);
1479
if (dpif->epoll_fd >= 0) {
1480
poll_fd_wait(dpif->epoll_fd, POLLIN);
1363
poll_fd_wait(dpif->epoll_fd, POLLIN);
1482
ovs_mutex_unlock(&dpif->upcall_lock);
1367
1486
dpif_linux_recv_purge(struct dpif *dpif_)
1369
1488
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
1370
struct dpif_channel *ch;
1372
if (dpif->epoll_fd < 0) {
1376
for (ch = dpif->channels; ch < &dpif->channels[dpif->uc_array_size]; ch++) {
1378
nl_sock_drain(ch->sock);
1490
ovs_mutex_lock(&dpif->upcall_lock);
1491
if (dpif->epoll_fd >= 0) {
1492
struct dpif_channel *ch;
1494
for (ch = dpif->channels; ch < &dpif->channels[dpif->uc_array_size];
1497
nl_sock_drain(ch->sock);
1501
ovs_mutex_unlock(&dpif->upcall_lock);
1383
1504
const struct dpif_class dpif_linux_class = {
1443
1563
&ovs_packet_family);
1446
error = nl_sock_create(NETLINK_GENERIC, &genl_sock);
1449
1566
error = nl_lookup_genl_mcgroup(OVS_VPORT_FAMILY, OVS_VPORT_MCGROUP,
1450
1567
&ovs_vport_mcgroup,
1451
1568
OVS_VPORT_MCGROUP_FALLBACK_ID);
1454
static struct dpif_linux_vport vport;
1455
nln = nln_create(NETLINK_GENERIC, ovs_vport_mcgroup,
1456
dpif_linux_nln_parse, &vport);
1571
ovsthread_once_done(&once);
1472
1586
ofpbuf_delete(buf);
1473
1587
} else if (error != ENODEV && error != ENOENT) {
1474
1588
VLOG_WARN_RL(&error_rl, "%s: vport query failed (%s)",
1475
name, strerror(error));
1589
name, ovs_strerror(error));
1478
1592
return reply.type == OVS_VPORT_TYPE_INTERNAL;
1482
dpif_linux_nln_parse(struct ofpbuf *buf, void *vport_)
1484
struct dpif_linux_vport *vport = vport_;
1485
return dpif_linux_vport_from_ofpbuf(vport, buf) == 0;
1489
dpif_linux_port_changed(const void *vport_, void *dpif_)
1491
const struct dpif_linux_vport *vport = vport_;
1492
struct dpif_linux *dpif = dpif_;
1495
if (vport->dp_ifindex == dpif->dp_ifindex
1496
&& (vport->cmd == OVS_VPORT_CMD_NEW
1497
|| vport->cmd == OVS_VPORT_CMD_DEL
1498
|| vport->cmd == OVS_VPORT_CMD_SET)) {
1499
VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8,
1500
dpif->dpif.full_name, vport->name, vport->cmd);
1501
sset_add(&dpif->changed_ports, vport->name);
1504
dpif->change_error = true;
1508
1595
/* Parses the contents of 'buf', which contains a "struct ovs_header" followed
1509
1596
* by Netlink attributes, into 'vport'. Returns 0 if successful, otherwise a
1547
1634
vport->cmd = genl->cmd;
1548
1635
vport->dp_ifindex = ovs_header->dp_ifindex;
1549
vport->port_no = nl_attr_get_u32(a[OVS_VPORT_ATTR_PORT_NO]);
1636
vport->port_no = nl_attr_get_odp_port(a[OVS_VPORT_ATTR_PORT_NO]);
1550
1637
vport->type = nl_attr_get_u32(a[OVS_VPORT_ATTR_TYPE]);
1551
1638
vport->name = nl_attr_get_string(a[OVS_VPORT_ATTR_NAME]);
1552
1639
if (a[OVS_VPORT_ATTR_UPCALL_PID]) {
1576
1663
ovs_header = ofpbuf_put_uninit(buf, sizeof *ovs_header);
1577
1664
ovs_header->dp_ifindex = vport->dp_ifindex;
1579
if (vport->port_no != UINT32_MAX) {
1580
nl_msg_put_u32(buf, OVS_VPORT_ATTR_PORT_NO, vport->port_no);
1666
if (vport->port_no != ODPP_NONE) {
1667
nl_msg_put_odp_port(buf, OVS_VPORT_ATTR_PORT_NO, vport->port_no);
1583
1670
if (vport->type != OVS_VPORT_TYPE_UNSPEC) {
1608
1695
dpif_linux_vport_init(struct dpif_linux_vport *vport)
1610
1697
memset(vport, 0, sizeof *vport);
1611
vport->port_no = UINT32_MAX;
1698
vport->port_no = ODPP_NONE;
1614
1701
/* Executes 'request' in the kernel datapath. If the command fails, returns a
1639
1726
request_buf = ofpbuf_new(1024);
1640
1727
dpif_linux_vport_to_ofpbuf(request, request_buf);
1641
error = nl_sock_transact(genl_sock, request_buf, bufp);
1728
error = nl_transact(NETLINK_GENERIC, request_buf, bufp);
1642
1729
ofpbuf_delete(request_buf);
1760
1847
buf = ofpbuf_new(1024);
1761
1848
dpif_linux_dp_to_ofpbuf(&request, buf);
1762
nl_dump_start(dump, genl_sock, buf);
1849
nl_dump_start(dump, NETLINK_GENERIC, buf);
1763
1850
ofpbuf_delete(buf);
1781
1868
request_buf = ofpbuf_new(1024);
1782
1869
dpif_linux_dp_to_ofpbuf(request, request_buf);
1783
error = nl_sock_transact(genl_sock, request_buf, bufp);
1870
error = nl_transact(NETLINK_GENERIC, request_buf, bufp);
1784
1871
ofpbuf_delete(request_buf);
1826
1913
static const struct nl_policy ovs_flow_policy[] = {
1827
1914
[OVS_FLOW_ATTR_KEY] = { .type = NL_A_NESTED },
1915
[OVS_FLOW_ATTR_MASK] = { .type = NL_A_NESTED, .optional = true },
1828
1916
[OVS_FLOW_ATTR_ACTIONS] = { .type = NL_A_NESTED, .optional = true },
1829
1917
[OVS_FLOW_ATTR_STATS] = { NL_POLICY_FOR(struct ovs_flow_stats),
1830
1918
.optional = true },
1856
1944
flow->dp_ifindex = ovs_header->dp_ifindex;
1857
1945
flow->key = nl_attr_get(a[OVS_FLOW_ATTR_KEY]);
1858
1946
flow->key_len = nl_attr_get_size(a[OVS_FLOW_ATTR_KEY]);
1948
if (a[OVS_FLOW_ATTR_MASK]) {
1949
flow->mask = nl_attr_get(a[OVS_FLOW_ATTR_MASK]);
1950
flow->mask_len = nl_attr_get_size(a[OVS_FLOW_ATTR_MASK]);
1859
1952
if (a[OVS_FLOW_ATTR_ACTIONS]) {
1860
1953
flow->actions = nl_attr_get(a[OVS_FLOW_ATTR_ACTIONS]);
1861
1954
flow->actions_len = nl_attr_get_size(a[OVS_FLOW_ATTR_ACTIONS]);
1891
1984
nl_msg_put_unspec(buf, OVS_FLOW_ATTR_KEY, flow->key, flow->key_len);
1987
if (flow->mask_len) {
1988
nl_msg_put_unspec(buf, OVS_FLOW_ATTR_MASK, flow->mask, flow->mask_len);
1894
1991
if (flow->actions || flow->actions_len) {
1895
1992
nl_msg_put_unspec(buf, OVS_FLOW_ATTR_ACTIONS,
1896
1993
flow->actions, flow->actions_len);
1935
2032
request_buf = ofpbuf_new(1024);
1936
2033
dpif_linux_flow_to_ofpbuf(request, request_buf);
1937
error = nl_sock_transact(genl_sock, request_buf, bufp);
2034
error = nl_transact(NETLINK_GENERIC, request_buf, bufp);
1938
2035
ofpbuf_delete(request_buf);