]> git.proxmox.com Git - mirror_ovs.git/blob - lib/dpif-linux.c
Rename UNUSED macro to OVS_UNUSED to avoid naming conflict.
[mirror_ovs.git] / lib / dpif-linux.c
1 /*
2 * Copyright (c) 2008, 2009, 2010 Nicira Networks.
3 *
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <config.h>
18 #include "dpif.h"
19
20 #include <assert.h>
21 #include <ctype.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <inttypes.h>
25 #include <net/if.h>
26 #include <linux/ethtool.h>
27 #include <linux/rtnetlink.h>
28 #include <linux/sockios.h>
29 #include <stdlib.h>
30 #include <sys/ioctl.h>
31 #include <unistd.h>
32
33 #include "dpif-provider.h"
34 #include "ofpbuf.h"
35 #include "poll-loop.h"
36 #include "rtnetlink.h"
37 #include "svec.h"
38 #include "util.h"
39
40 #include "vlog.h"
41 #define THIS_MODULE VLM_dpif_linux
42
43 /* Datapath interface for the openvswitch Linux kernel module. */
44 struct dpif_linux {
45 struct dpif dpif;
46 int fd;
47
48 /* Used by dpif_linux_get_all_names(). */
49 char *local_ifname;
50 int minor;
51
52 /* Change notification. */
53 int local_ifindex; /* Ifindex of local port. */
54 struct svec changed_ports; /* Ports that have changed. */
55 struct rtnetlink_notifier port_notifier;
56 bool change_error;
57 };
58
59 static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(9999, 5);
60
61 static int do_ioctl(const struct dpif *, int cmd, const void *arg);
62 static int lookup_minor(const char *name, int *minor);
63 static int finish_open(struct dpif *, const char *local_ifname);
64 static int get_openvswitch_major(void);
65 static int create_minor(const char *name, int minor, struct dpif **dpifp);
66 static int open_minor(int minor, struct dpif **dpifp);
67 static int make_openvswitch_device(int minor, char **fnp);
68 static void dpif_linux_port_changed(const struct rtnetlink_change *,
69 void *dpif);
70
71 static struct dpif_linux *
72 dpif_linux_cast(const struct dpif *dpif)
73 {
74 dpif_assert_class(dpif, &dpif_linux_class);
75 return CONTAINER_OF(dpif, struct dpif_linux, dpif);
76 }
77
78 static int
79 dpif_linux_enumerate(struct svec *all_dps)
80 {
81 int major;
82 int error;
83 int i;
84
85 /* Check that the Open vSwitch module is loaded. */
86 major = get_openvswitch_major();
87 if (major < 0) {
88 return -major;
89 }
90
91 error = 0;
92 for (i = 0; i < ODP_MAX; i++) {
93 struct dpif *dpif;
94 char devname[16];
95 int retval;
96
97 sprintf(devname, "dp%d", i);
98 retval = dpif_open(devname, &dpif);
99 if (!retval) {
100 svec_add(all_dps, devname);
101 dpif_close(dpif);
102 } else if (retval != ENODEV && !error) {
103 error = retval;
104 }
105 }
106 return error;
107 }
108
109 static int
110 dpif_linux_open(const char *name OVS_UNUSED, char *suffix, bool create,
111 struct dpif **dpifp)
112 {
113 int minor;
114
115 minor = !strncmp(name, "dp", 2)
116 && isdigit((unsigned char)name[2]) ? atoi(name + 2) : -1;
117 if (create) {
118 if (minor >= 0) {
119 return create_minor(suffix, minor, dpifp);
120 } else {
121 /* Scan for unused minor number. */
122 for (minor = 0; minor < ODP_MAX; minor++) {
123 int error = create_minor(suffix, minor, dpifp);
124 if (error != EBUSY) {
125 return error;
126 }
127 }
128
129 /* All datapath numbers in use. */
130 return ENOBUFS;
131 }
132 } else {
133 struct dpif_linux *dpif;
134 struct odp_port port;
135 int error;
136
137 if (minor < 0) {
138 error = lookup_minor(suffix, &minor);
139 if (error) {
140 return error;
141 }
142 }
143
144 error = open_minor(minor, dpifp);
145 if (error) {
146 return error;
147 }
148 dpif = dpif_linux_cast(*dpifp);
149
150 /* We need the local port's ifindex for the poll function. Start by
151 * getting the local port's name. */
152 memset(&port, 0, sizeof port);
153 port.port = ODPP_LOCAL;
154 if (ioctl(dpif->fd, ODP_PORT_QUERY, &port)) {
155 error = errno;
156 if (error != ENODEV) {
157 VLOG_WARN("%s: probe returned unexpected error: %s",
158 dpif_name(*dpifp), strerror(error));
159 }
160 dpif_close(*dpifp);
161 return error;
162 }
163
164 /* Then use that to finish up opening. */
165 return finish_open(&dpif->dpif, port.devname);
166 }
167 }
168
169 static void
170 dpif_linux_close(struct dpif *dpif_)
171 {
172 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
173 rtnetlink_notifier_unregister(&dpif->port_notifier);
174 svec_destroy(&dpif->changed_ports);
175 free(dpif->local_ifname);
176 close(dpif->fd);
177 free(dpif);
178 }
179
180 static int
181 dpif_linux_get_all_names(const struct dpif *dpif_, struct svec *all_names)
182 {
183 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
184
185 svec_add_nocopy(all_names, xasprintf("dp%d", dpif->minor));
186 svec_add(all_names, dpif->local_ifname);
187 return 0;
188 }
189
190 static int
191 dpif_linux_delete(struct dpif *dpif_)
192 {
193 return do_ioctl(dpif_, ODP_DP_DESTROY, NULL);
194 }
195
196 static int
197 dpif_linux_get_stats(const struct dpif *dpif_, struct odp_stats *stats)
198 {
199 memset(stats, 0, sizeof *stats);
200 return do_ioctl(dpif_, ODP_DP_STATS, stats);
201 }
202
203 static int
204 dpif_linux_get_drop_frags(const struct dpif *dpif_, bool *drop_fragsp)
205 {
206 int drop_frags;
207 int error;
208
209 error = do_ioctl(dpif_, ODP_GET_DROP_FRAGS, &drop_frags);
210 if (!error) {
211 *drop_fragsp = drop_frags & 1;
212 }
213 return error;
214 }
215
216 static int
217 dpif_linux_set_drop_frags(struct dpif *dpif_, bool drop_frags)
218 {
219 int drop_frags_int = drop_frags;
220 return do_ioctl(dpif_, ODP_SET_DROP_FRAGS, &drop_frags_int);
221 }
222
223 static int
224 dpif_linux_port_add(struct dpif *dpif_, const char *devname, uint16_t flags,
225 uint16_t *port_no)
226 {
227 struct odp_port port;
228 int error;
229
230 memset(&port, 0, sizeof port);
231 strncpy(port.devname, devname, sizeof port.devname);
232 port.flags = flags;
233 error = do_ioctl(dpif_, ODP_PORT_ADD, &port);
234 if (!error) {
235 *port_no = port.port;
236 }
237 return error;
238 }
239
240 static int
241 dpif_linux_port_del(struct dpif *dpif_, uint16_t port_no)
242 {
243 int tmp = port_no;
244 return do_ioctl(dpif_, ODP_PORT_DEL, &tmp);
245 }
246
247 static int
248 dpif_linux_port_query_by_number(const struct dpif *dpif_, uint16_t port_no,
249 struct odp_port *port)
250 {
251 memset(port, 0, sizeof *port);
252 port->port = port_no;
253 return do_ioctl(dpif_, ODP_PORT_QUERY, port);
254 }
255
256 static int
257 dpif_linux_port_query_by_name(const struct dpif *dpif_, const char *devname,
258 struct odp_port *port)
259 {
260 memset(port, 0, sizeof *port);
261 strncpy(port->devname, devname, sizeof port->devname);
262 return do_ioctl(dpif_, ODP_PORT_QUERY, port);
263 }
264
265 static int
266 dpif_linux_flow_flush(struct dpif *dpif_)
267 {
268 return do_ioctl(dpif_, ODP_FLOW_FLUSH, NULL);
269 }
270
271 static int
272 dpif_linux_port_list(const struct dpif *dpif_, struct odp_port *ports, int n)
273 {
274 struct odp_portvec pv;
275 int error;
276
277 pv.ports = ports;
278 pv.n_ports = n;
279 error = do_ioctl(dpif_, ODP_PORT_LIST, &pv);
280 return error ? -error : pv.n_ports;
281 }
282
283 static int
284 dpif_linux_port_poll(const struct dpif *dpif_, char **devnamep)
285 {
286 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
287
288 if (dpif->change_error) {
289 dpif->change_error = false;
290 svec_clear(&dpif->changed_ports);
291 return ENOBUFS;
292 } else if (dpif->changed_ports.n) {
293 *devnamep = dpif->changed_ports.names[--dpif->changed_ports.n];
294 return 0;
295 } else {
296 return EAGAIN;
297 }
298 }
299
300 static void
301 dpif_linux_port_poll_wait(const struct dpif *dpif_)
302 {
303 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
304 if (dpif->changed_ports.n || dpif->change_error) {
305 poll_immediate_wake();
306 } else {
307 rtnetlink_notifier_wait();
308 }
309 }
310
311 static int
312 dpif_linux_port_group_get(const struct dpif *dpif_, int group,
313 uint16_t ports[], int n)
314 {
315 struct odp_port_group pg;
316 int error;
317
318 assert(n <= UINT16_MAX);
319 pg.group = group;
320 pg.ports = ports;
321 pg.n_ports = n;
322 error = do_ioctl(dpif_, ODP_PORT_GROUP_GET, &pg);
323 return error ? -error : pg.n_ports;
324 }
325
326 static int
327 dpif_linux_port_group_set(struct dpif *dpif_, int group,
328 const uint16_t ports[], int n)
329 {
330 struct odp_port_group pg;
331
332 assert(n <= UINT16_MAX);
333 pg.group = group;
334 pg.ports = (uint16_t *) ports;
335 pg.n_ports = n;
336 return do_ioctl(dpif_, ODP_PORT_GROUP_SET, &pg);
337 }
338
339 static int
340 dpif_linux_flow_get(const struct dpif *dpif_, struct odp_flow flows[], int n)
341 {
342 struct odp_flowvec fv;
343 fv.flows = flows;
344 fv.n_flows = n;
345 return do_ioctl(dpif_, ODP_FLOW_GET, &fv);
346 }
347
348 static int
349 dpif_linux_flow_put(struct dpif *dpif_, struct odp_flow_put *put)
350 {
351 return do_ioctl(dpif_, ODP_FLOW_PUT, put);
352 }
353
354 static int
355 dpif_linux_flow_del(struct dpif *dpif_, struct odp_flow *flow)
356 {
357 return do_ioctl(dpif_, ODP_FLOW_DEL, flow);
358 }
359
360 static int
361 dpif_linux_flow_list(const struct dpif *dpif_, struct odp_flow flows[], int n)
362 {
363 struct odp_flowvec fv;
364 int error;
365
366 fv.flows = flows;
367 fv.n_flows = n;
368 error = do_ioctl(dpif_, ODP_FLOW_LIST, &fv);
369 return error ? -error : fv.n_flows;
370 }
371
372 static int
373 dpif_linux_execute(struct dpif *dpif_, uint16_t in_port,
374 const union odp_action actions[], int n_actions,
375 const struct ofpbuf *buf)
376 {
377 struct odp_execute execute;
378 memset(&execute, 0, sizeof execute);
379 execute.in_port = in_port;
380 execute.actions = (union odp_action *) actions;
381 execute.n_actions = n_actions;
382 execute.data = buf->data;
383 execute.length = buf->size;
384 return do_ioctl(dpif_, ODP_EXECUTE, &execute);
385 }
386
387 static int
388 dpif_linux_recv_get_mask(const struct dpif *dpif_, int *listen_mask)
389 {
390 return do_ioctl(dpif_, ODP_GET_LISTEN_MASK, listen_mask);
391 }
392
393 static int
394 dpif_linux_recv_set_mask(struct dpif *dpif_, int listen_mask)
395 {
396 return do_ioctl(dpif_, ODP_SET_LISTEN_MASK, &listen_mask);
397 }
398
399 static int
400 dpif_linux_get_sflow_probability(const struct dpif *dpif_,
401 uint32_t *probability)
402 {
403 return do_ioctl(dpif_, ODP_GET_SFLOW_PROBABILITY, probability);
404 }
405
406 static int
407 dpif_linux_set_sflow_probability(struct dpif *dpif_, uint32_t probability)
408 {
409 return do_ioctl(dpif_, ODP_SET_SFLOW_PROBABILITY, &probability);
410 }
411
412 static int
413 dpif_linux_recv(struct dpif *dpif_, struct ofpbuf **bufp)
414 {
415 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
416 struct ofpbuf *buf;
417 int retval;
418 int error;
419
420 buf = ofpbuf_new(65536);
421 retval = read(dpif->fd, ofpbuf_tail(buf), ofpbuf_tailroom(buf));
422 if (retval < 0) {
423 error = errno;
424 if (error != EAGAIN) {
425 VLOG_WARN_RL(&error_rl, "%s: read failed: %s",
426 dpif_name(dpif_), strerror(error));
427 }
428 } else if (retval >= sizeof(struct odp_msg)) {
429 struct odp_msg *msg = buf->data;
430 if (msg->length <= retval) {
431 buf->size += retval;
432 *bufp = buf;
433 return 0;
434 } else {
435 VLOG_WARN_RL(&error_rl, "%s: discarding message truncated "
436 "from %"PRIu32" bytes to %d",
437 dpif_name(dpif_), msg->length, retval);
438 error = ERANGE;
439 }
440 } else if (!retval) {
441 VLOG_WARN_RL(&error_rl, "%s: unexpected end of file", dpif_name(dpif_));
442 error = EPROTO;
443 } else {
444 VLOG_WARN_RL(&error_rl,
445 "%s: discarding too-short message (%d bytes)",
446 dpif_name(dpif_), retval);
447 error = ERANGE;
448 }
449
450 *bufp = NULL;
451 ofpbuf_delete(buf);
452 return error;
453 }
454
455 static void
456 dpif_linux_recv_wait(struct dpif *dpif_)
457 {
458 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
459 poll_fd_wait(dpif->fd, POLLIN);
460 }
461
462 const struct dpif_class dpif_linux_class = {
463 "", /* This is the default class. */
464 "linux",
465 NULL,
466 NULL,
467 dpif_linux_enumerate,
468 dpif_linux_open,
469 dpif_linux_close,
470 dpif_linux_get_all_names,
471 dpif_linux_delete,
472 dpif_linux_get_stats,
473 dpif_linux_get_drop_frags,
474 dpif_linux_set_drop_frags,
475 dpif_linux_port_add,
476 dpif_linux_port_del,
477 dpif_linux_port_query_by_number,
478 dpif_linux_port_query_by_name,
479 dpif_linux_port_list,
480 dpif_linux_port_poll,
481 dpif_linux_port_poll_wait,
482 dpif_linux_port_group_get,
483 dpif_linux_port_group_set,
484 dpif_linux_flow_get,
485 dpif_linux_flow_put,
486 dpif_linux_flow_del,
487 dpif_linux_flow_flush,
488 dpif_linux_flow_list,
489 dpif_linux_execute,
490 dpif_linux_recv_get_mask,
491 dpif_linux_recv_set_mask,
492 dpif_linux_get_sflow_probability,
493 dpif_linux_set_sflow_probability,
494 dpif_linux_recv,
495 dpif_linux_recv_wait,
496 };
497 \f
498 static int get_openvswitch_major(void);
499 static int get_major(const char *target);
500
501 static int
502 do_ioctl(const struct dpif *dpif_, int cmd, const void *arg)
503 {
504 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
505 return ioctl(dpif->fd, cmd, arg) ? errno : 0;
506 }
507
508 static int
509 lookup_minor(const char *name, int *minorp)
510 {
511 struct ethtool_drvinfo drvinfo;
512 int minor, port_no;
513 struct ifreq ifr;
514 int error;
515 int sock;
516
517 sock = socket(AF_INET, SOCK_DGRAM, 0);
518 if (sock < 0) {
519 VLOG_WARN("socket(AF_INET) failed: %s", strerror(errno));
520 error = errno;
521 goto error;
522 }
523
524 memset(&ifr, 0, sizeof ifr);
525 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
526 ifr.ifr_data = (caddr_t) &drvinfo;
527
528 memset(&drvinfo, 0, sizeof drvinfo);
529 drvinfo.cmd = ETHTOOL_GDRVINFO;
530 if (ioctl(sock, SIOCETHTOOL, &ifr)) {
531 VLOG_WARN("ioctl(SIOCETHTOOL) failed: %s", strerror(errno));
532 error = errno;
533 goto error_close_sock;
534 }
535
536 if (strcmp(drvinfo.driver, "openvswitch")) {
537 VLOG_WARN("%s is not an openvswitch device", name);
538 error = EOPNOTSUPP;
539 goto error_close_sock;
540 }
541
542 if (sscanf(drvinfo.bus_info, "%d.%d", &minor, &port_no) != 2) {
543 VLOG_WARN("%s ethtool bus_info has unexpected format", name);
544 error = EPROTOTYPE;
545 goto error_close_sock;
546 } else if (port_no != ODPP_LOCAL) {
547 /* This is an Open vSwitch device but not the local port. We
548 * intentionally support only using the name of the local port as the
549 * name of a datapath; otherwise, it would be too difficult to
550 * enumerate all the names of a datapath. */
551 error = EOPNOTSUPP;
552 goto error_close_sock;
553 }
554
555 *minorp = minor;
556 close(sock);
557 return 0;
558
559 error_close_sock:
560 close(sock);
561 error:
562 return error;
563 }
564
565 static int
566 make_openvswitch_device(int minor, char **fnp)
567 {
568 const char dirname[] = "/dev/net";
569 int major;
570 dev_t dev;
571 struct stat s;
572 char fn[128];
573
574 *fnp = NULL;
575
576 major = get_openvswitch_major();
577 if (major < 0) {
578 return -major;
579 }
580 dev = makedev(major, minor);
581
582 sprintf(fn, "%s/dp%d", dirname, minor);
583 if (!stat(fn, &s)) {
584 if (!S_ISCHR(s.st_mode)) {
585 VLOG_WARN_RL(&error_rl, "%s is not a character device, fixing",
586 fn);
587 } else if (s.st_rdev != dev) {
588 VLOG_WARN_RL(&error_rl,
589 "%s is device %u:%u but should be %u:%u, fixing",
590 fn, major(s.st_rdev), minor(s.st_rdev),
591 major(dev), minor(dev));
592 } else {
593 goto success;
594 }
595 if (unlink(fn)) {
596 VLOG_WARN_RL(&error_rl, "%s: unlink failed (%s)",
597 fn, strerror(errno));
598 return errno;
599 }
600 } else if (errno == ENOENT) {
601 if (stat(dirname, &s)) {
602 if (errno == ENOENT) {
603 if (mkdir(dirname, 0755)) {
604 VLOG_WARN_RL(&error_rl, "%s: mkdir failed (%s)",
605 dirname, strerror(errno));
606 return errno;
607 }
608 } else {
609 VLOG_WARN_RL(&error_rl, "%s: stat failed (%s)",
610 dirname, strerror(errno));
611 return errno;
612 }
613 }
614 } else {
615 VLOG_WARN_RL(&error_rl, "%s: stat failed (%s)", fn, strerror(errno));
616 return errno;
617 }
618
619 /* The device needs to be created. */
620 if (mknod(fn, S_IFCHR | 0700, dev)) {
621 VLOG_WARN_RL(&error_rl,
622 "%s: creating character device %u:%u failed (%s)",
623 fn, major(dev), minor(dev), strerror(errno));
624 return errno;
625 }
626
627 success:
628 *fnp = xstrdup(fn);
629 return 0;
630 }
631
632 /* Return the major device number of the Open vSwitch device. If it
633 * cannot be determined, a negative errno is returned. */
634 static int
635 get_openvswitch_major(void)
636 {
637 static int openvswitch_major = -1;
638 if (openvswitch_major < 0) {
639 openvswitch_major = get_major("openvswitch");
640 }
641 return openvswitch_major;
642 }
643
644 static int
645 get_major(const char *target)
646 {
647 const char fn[] = "/proc/devices";
648 char line[128];
649 FILE *file;
650 int ln;
651
652 file = fopen(fn, "r");
653 if (!file) {
654 VLOG_ERR("opening %s failed (%s)", fn, strerror(errno));
655 return -errno;
656 }
657
658 for (ln = 1; fgets(line, sizeof line, file); ln++) {
659 char name[64];
660 int major;
661
662 if (!strncmp(line, "Character", 9) || line[0] == '\0') {
663 /* Nothing to do. */
664 } else if (!strncmp(line, "Block", 5)) {
665 /* We only want character devices, so skip the rest of the file. */
666 break;
667 } else if (sscanf(line, "%d %63s", &major, name)) {
668 if (!strcmp(name, target)) {
669 fclose(file);
670 return major;
671 }
672 } else {
673 static bool warned;
674 if (!warned) {
675 VLOG_WARN("%s:%d: syntax error", fn, ln);
676 }
677 warned = true;
678 }
679 }
680
681 VLOG_ERR("%s: %s major not found (is the module loaded?)", fn, target);
682 return -ENODEV;
683 }
684
685 static int
686 finish_open(struct dpif *dpif_, const char *local_ifname)
687 {
688 struct dpif_linux *dpif = dpif_linux_cast(dpif_);
689 dpif->local_ifname = strdup(local_ifname);
690 dpif->local_ifindex = if_nametoindex(local_ifname);
691 if (!dpif->local_ifindex) {
692 int error = errno;
693 dpif_close(dpif_);
694 VLOG_WARN("could not get ifindex of %s device: %s",
695 local_ifname, strerror(errno));
696 return error;
697 }
698 return 0;
699 }
700
701 static int
702 create_minor(const char *name, int minor, struct dpif **dpifp)
703 {
704 int error = open_minor(minor, dpifp);
705 if (!error) {
706 error = do_ioctl(*dpifp, ODP_DP_CREATE, name);
707 if (!error) {
708 error = finish_open(*dpifp, name);
709 } else {
710 dpif_close(*dpifp);
711 }
712 }
713 return error;
714 }
715
716 static int
717 open_minor(int minor, struct dpif **dpifp)
718 {
719 int error;
720 char *fn;
721 int fd;
722
723 error = make_openvswitch_device(minor, &fn);
724 if (error) {
725 return error;
726 }
727
728 fd = open(fn, O_RDONLY | O_NONBLOCK);
729 if (fd >= 0) {
730 struct dpif_linux *dpif = xmalloc(sizeof *dpif);
731 error = rtnetlink_notifier_register(&dpif->port_notifier,
732 dpif_linux_port_changed, dpif);
733 if (!error) {
734 char *name;
735
736 name = xasprintf("dp%d", minor);
737 dpif_init(&dpif->dpif, &dpif_linux_class, name, minor, minor);
738 free(name);
739
740 dpif->fd = fd;
741 dpif->local_ifname = NULL;
742 dpif->minor = minor;
743 dpif->local_ifindex = 0;
744 svec_init(&dpif->changed_ports);
745 dpif->change_error = false;
746 *dpifp = &dpif->dpif;
747 } else {
748 free(dpif);
749 }
750 } else {
751 error = errno;
752 VLOG_WARN("%s: open failed (%s)", fn, strerror(error));
753 }
754 free(fn);
755
756 return error;
757 }
758
759 static void
760 dpif_linux_port_changed(const struct rtnetlink_change *change, void *dpif_)
761 {
762 struct dpif_linux *dpif = dpif_;
763
764 if (change) {
765 if (change->master_ifindex == dpif->local_ifindex
766 && (change->nlmsg_type == RTM_NEWLINK
767 || change->nlmsg_type == RTM_DELLINK))
768 {
769 /* Our datapath changed, either adding a new port or deleting an
770 * existing one. */
771 if (!svec_contains(&dpif->changed_ports, change->ifname)) {
772 svec_add(&dpif->changed_ports, change->ifname);
773 svec_sort(&dpif->changed_ports);
774 }
775 }
776 } else {
777 dpif->change_error = true;
778 }
779 }