2 * Copyright (c) 2008, 2009 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 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.
26 #include <linux/rtnetlink.h>
27 #include <linux/ethtool.h>
28 #include <linux/sockios.h>
29 #include <netinet/in.h>
32 #include <sys/ioctl.h>
34 #include <sys/sysmacros.h>
38 #include "dynamic-string.h"
42 #include "ofp-print.h"
45 #include "poll-loop.h"
50 #define THIS_MODULE VLM_dpif
52 /* Rate limit for individual messages going to or from the datapath, output at
53 * DBG level. This is very high because, if these are enabled, it is because
54 * we really need to see them. */
55 static struct vlog_rate_limit dpmsg_rl = VLOG_RATE_LIMIT_INIT(600, 600);
57 /* Not really much point in logging many dpif errors. */
58 static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(9999, 5);
60 static int get_minor_from_name(const char *name, unsigned int *minor);
61 static int name_to_minor(const char *name, unsigned int *minor);
62 static int lookup_minor(const char *name, unsigned int *minor);
63 static int open_by_minor(unsigned int minor, struct dpif *);
64 static int make_openvswitch_device(unsigned int minor, char **fnp);
65 static void check_rw_odp_flow(struct odp_flow *);
68 dpif_open(const char *name, struct dpif *dpif)
75 error = name_to_minor(name, &dpif->minor);
80 error = open_by_minor(dpif->minor, dpif);
85 /* We can open the device, but that doesn't mean that it's been created.
86 * If it hasn't been, then any command other than ODP_DP_CREATE will
87 * return ENODEV. Try something innocuous. */
88 listen_mask = 0; /* Make Valgrind happy. */
89 if (ioctl(dpif->fd, ODP_GET_LISTEN_MASK, &listen_mask)) {
91 if (error != ENODEV) {
92 VLOG_WARN("dp%u: probe returned unexpected error: %s",
93 dpif->minor, strerror(error));
102 dpif_close(struct dpif *dpif)
111 do_ioctl(const struct dpif *dpif, int cmd, const char *cmd_name,
114 int error = ioctl(dpif->fd, cmd, arg) ? errno : 0;
117 VLOG_WARN_RL(&error_rl, "dp%u: ioctl(%s) failed (%s)",
118 dpif->minor, cmd_name, strerror(error));
120 VLOG_DBG_RL(&dpmsg_rl, "dp%u: ioctl(%s): success",
121 dpif->minor, cmd_name);
128 dpif_create(const char *name, struct dpif *dpif)
133 if (!get_minor_from_name(name, &minor)) {
134 /* Minor was specified in 'name', go ahead and create it. */
135 error = open_by_minor(minor, dpif);
140 if (!strncmp(name, "nl:", 3)) {
142 sprintf(devname, "of%u", minor);
143 error = ioctl(dpif->fd, ODP_DP_CREATE, devname) < 0 ? errno : 0;
145 error = ioctl(dpif->fd, ODP_DP_CREATE, name) < 0 ? errno : 0;
152 for (minor = 0; minor < ODP_MAX; minor++) {
153 error = open_by_minor(minor, dpif);
158 error = ioctl(dpif->fd, ODP_DP_CREATE, name) < 0 ? errno : 0;
163 if (error != EBUSY) {
172 dpif_delete(struct dpif *dpif)
174 COVERAGE_INC(dpif_destroy);
175 return do_ioctl(dpif, ODP_DP_DESTROY, "ODP_DP_DESTROY", NULL);
179 dpif_get_dp_stats(const struct dpif *dpif, struct odp_stats *stats)
181 memset(stats, 0, sizeof *stats);
182 return do_ioctl(dpif, ODP_DP_STATS, "ODP_DP_STATS", stats);
186 dpif_get_drop_frags(const struct dpif *dpif, bool *drop_frags)
189 int error = do_ioctl(dpif, ODP_GET_DROP_FRAGS, "ODP_GET_DROP_FRAGS", &tmp);
190 *drop_frags = error ? tmp & 1 : false;
195 dpif_set_drop_frags(struct dpif *dpif, bool drop_frags)
197 int tmp = drop_frags;
198 return do_ioctl(dpif, ODP_SET_DROP_FRAGS, "ODP_SET_DROP_FRAGS", &tmp);
202 dpif_get_listen_mask(const struct dpif *dpif, int *listen_mask)
204 int error = do_ioctl(dpif, ODP_GET_LISTEN_MASK, "ODP_GET_LISTEN_MASK",
213 dpif_set_listen_mask(struct dpif *dpif, int listen_mask)
215 return do_ioctl(dpif, ODP_SET_LISTEN_MASK, "ODP_SET_LISTEN_MASK",
220 dpif_purge(struct dpif *dpif)
222 struct odp_stats stats;
226 COVERAGE_INC(dpif_purge);
228 error = dpif_get_dp_stats(dpif, &stats);
233 for (i = 0; i < stats.max_miss_queue + stats.max_action_queue; i++) {
235 error = dpif_recv(dpif, &buf);
237 return error == EAGAIN ? 0 : error;
245 dpif_port_add(struct dpif *dpif, const char *devname, uint16_t port_no,
248 struct odp_port port;
250 COVERAGE_INC(dpif_port_add);
251 memset(&port, 0, sizeof port);
252 strncpy(port.devname, devname, sizeof port.devname);
255 if (!ioctl(dpif->fd, ODP_PORT_ADD, &port)) {
256 VLOG_DBG_RL(&dpmsg_rl, "dp%u: added %s as port %"PRIu16,
257 dpif->minor, devname, port_no);
260 VLOG_WARN_RL(&error_rl, "dp%u: failed to add %s as port "
261 "%"PRIu16": %s", dpif->minor, devname, port_no,
268 dpif_port_del(struct dpif *dpif, uint16_t port_no)
271 COVERAGE_INC(dpif_port_del);
272 return do_ioctl(dpif, ODP_PORT_DEL, "ODP_PORT_DEL", &tmp);
276 dpif_port_query_by_number(const struct dpif *dpif, uint16_t port_no,
277 struct odp_port *port)
279 memset(port, 0, sizeof *port);
280 port->port = port_no;
281 if (!ioctl(dpif->fd, ODP_PORT_QUERY, port)) {
282 VLOG_DBG_RL(&dpmsg_rl, "dp%u: port %"PRIu16" is device %s",
283 dpif->minor, port_no, port->devname);
286 VLOG_WARN_RL(&error_rl, "dp%u: failed to query port %"PRIu16": %s",
287 dpif->minor, port_no, strerror(errno));
293 dpif_port_query_by_name(const struct dpif *dpif, const char *devname,
294 struct odp_port *port)
296 memset(port, 0, sizeof *port);
297 strncpy(port->devname, devname, sizeof port->devname);
298 if (!ioctl(dpif->fd, ODP_PORT_QUERY, port)) {
299 VLOG_DBG_RL(&dpmsg_rl, "dp%u: device %s is on port %"PRIu16,
300 dpif->minor, devname, port->port);
303 VLOG_WARN_RL(&error_rl, "dp%u: failed to query port %s: %s",
304 dpif->minor, devname, strerror(errno));
310 dpif_port_get_name(struct dpif *dpif, uint16_t port_no,
311 char *name, size_t name_size)
313 struct odp_port port;
316 assert(name_size > 0);
318 error = dpif_port_query_by_number(dpif, port_no, &port);
320 ovs_strlcpy(name, port.devname, name_size);
328 dpif_port_list(const struct dpif *dpif,
329 struct odp_port **ports, size_t *n_ports)
331 struct odp_portvec pv;
332 struct odp_stats stats;
336 error = dpif_get_dp_stats(dpif, &stats);
341 *ports = xcalloc(1, stats.n_ports * sizeof **ports);
343 pv.n_ports = stats.n_ports;
344 error = do_ioctl(dpif, ODP_PORT_LIST, "ODP_PORT_LIST", &pv);
349 } while (pv.n_ports != stats.n_ports);
350 *n_ports = pv.n_ports;
360 dpif_port_group_set(struct dpif *dpif, uint16_t group,
361 const uint16_t ports[], size_t n_ports)
363 struct odp_port_group pg;
365 COVERAGE_INC(dpif_port_group_set);
366 assert(n_ports <= UINT16_MAX);
368 pg.ports = (uint16_t *) ports;
369 pg.n_ports = n_ports;
370 return do_ioctl(dpif, ODP_PORT_GROUP_SET, "ODP_PORT_GROUP_SET", &pg);
373 /* Careful: '*n_out' can be greater than 'n_ports' on return, if 'n_ports' is
374 * less than the number of ports in 'group'. */
376 dpif_port_group_get(const struct dpif *dpif, uint16_t group,
377 uint16_t ports[], size_t n_ports, size_t *n_out)
379 struct odp_port_group pg;
382 assert(n_ports <= UINT16_MAX);
385 pg.n_ports = n_ports;
386 error = do_ioctl(dpif, ODP_PORT_GROUP_GET, "ODP_PORT_GROUP_GET", &pg);
387 *n_out = error ? 0 : pg.n_ports;
392 dpif_flow_flush(struct dpif *dpif)
394 COVERAGE_INC(dpif_flow_flush);
395 return do_ioctl(dpif, ODP_FLOW_FLUSH, "ODP_FLOW_FLUSH", NULL);
398 static enum vlog_level
399 flow_message_log_level(int error)
401 return error ? VLL_WARN : VLL_DBG;
405 should_log_flow_message(int error)
407 return !vlog_should_drop(THIS_MODULE, flow_message_log_level(error),
408 error ? &error_rl : &dpmsg_rl);
412 log_flow_message(const struct dpif *dpif, int error,
413 const char *operation,
414 const flow_t *flow, const struct odp_flow_stats *stats,
415 const union odp_action *actions, size_t n_actions)
417 struct ds ds = DS_EMPTY_INITIALIZER;
418 ds_put_format(&ds, "dp%u: ", dpif->minor);
420 ds_put_cstr(&ds, "failed to ");
422 ds_put_format(&ds, "%s ", operation);
424 ds_put_format(&ds, "(%s) ", strerror(error));
426 flow_format(&ds, flow);
428 ds_put_cstr(&ds, ", ");
429 format_odp_flow_stats(&ds, stats);
431 if (actions || n_actions) {
432 ds_put_cstr(&ds, ", actions:");
433 format_odp_actions(&ds, actions, n_actions);
435 vlog(THIS_MODULE, flow_message_log_level(error), "%s", ds_cstr(&ds));
440 do_flow_ioctl(const struct dpif *dpif, int cmd, struct odp_flow *flow,
441 const char *operation, bool show_stats)
443 int error = do_ioctl(dpif, cmd, NULL, flow);
444 if (error && show_stats) {
447 if (should_log_flow_message(error)) {
448 log_flow_message(dpif, error, operation, &flow->key,
449 show_stats && !error ? &flow->stats : NULL,
450 flow->actions, flow->n_actions);
456 dpif_flow_put(struct dpif *dpif, struct odp_flow_put *put)
458 int error = do_ioctl(dpif, ODP_FLOW_PUT, NULL, put);
459 COVERAGE_INC(dpif_flow_put);
460 if (should_log_flow_message(error)) {
461 struct ds operation = DS_EMPTY_INITIALIZER;
462 ds_put_cstr(&operation, "put");
463 if (put->flags & ODPPF_CREATE) {
464 ds_put_cstr(&operation, "[create]");
466 if (put->flags & ODPPF_MODIFY) {
467 ds_put_cstr(&operation, "[modify]");
469 if (put->flags & ODPPF_ZERO_STATS) {
470 ds_put_cstr(&operation, "[zero]");
472 #define ODPPF_ALL (ODPPF_CREATE | ODPPF_MODIFY | ODPPF_ZERO_STATS)
473 if (put->flags & ~ODPPF_ALL) {
474 ds_put_format(&operation, "[%x]", put->flags & ~ODPPF_ALL);
476 log_flow_message(dpif, error, ds_cstr(&operation), &put->flow.key,
477 !error ? &put->flow.stats : NULL,
478 put->flow.actions, put->flow.n_actions);
479 ds_destroy(&operation);
485 dpif_flow_del(struct dpif *dpif, struct odp_flow *flow)
487 COVERAGE_INC(dpif_flow_del);
488 check_rw_odp_flow(flow);
489 memset(&flow->stats, 0, sizeof flow->stats);
490 return do_flow_ioctl(dpif, ODP_FLOW_DEL, flow, "delete flow", true);
494 dpif_flow_get(const struct dpif *dpif, struct odp_flow *flow)
496 COVERAGE_INC(dpif_flow_query);
497 check_rw_odp_flow(flow);
498 memset(&flow->stats, 0, sizeof flow->stats);
499 return do_flow_ioctl(dpif, ODP_FLOW_GET, flow, "get flow", true);
503 dpif_flow_get_multiple(const struct dpif *dpif,
504 struct odp_flow flows[], size_t n)
506 struct odp_flowvec fv;
509 COVERAGE_ADD(dpif_flow_query_multiple, n);
512 for (i = 0; i < n; i++) {
513 check_rw_odp_flow(&flows[i]);
515 return do_ioctl(dpif, ODP_FLOW_GET_MULTIPLE, "ODP_FLOW_GET_MULTIPLE",
520 dpif_flow_list(const struct dpif *dpif, struct odp_flow flows[], size_t n,
523 struct odp_flowvec fv;
527 COVERAGE_INC(dpif_flow_query_list);
530 if (RUNNING_ON_VALGRIND) {
531 memset(flows, 0, n * sizeof *flows);
533 for (i = 0; i < n; i++) {
534 flows[i].actions = NULL;
535 flows[i].n_actions = 0;
538 error = do_ioctl(dpif, ODP_FLOW_LIST, NULL, &fv);
541 VLOG_WARN_RL(&error_rl, "dp%u: flow list failed (%s)",
542 dpif->minor, strerror(error));
544 COVERAGE_ADD(dpif_flow_query_list_n, fv.n_flows);
546 VLOG_DBG_RL(&dpmsg_rl, "dp%u: listed %zu flows", dpif->minor, *n_out);
552 dpif_flow_list_all(const struct dpif *dpif,
553 struct odp_flow **flowsp, size_t *np)
555 struct odp_stats stats;
556 struct odp_flow *flows;
563 error = dpif_get_dp_stats(dpif, &stats);
568 flows = xmalloc(sizeof *flows * stats.n_flows);
569 error = dpif_flow_list(dpif, flows, stats.n_flows, &n_flows);
575 if (stats.n_flows != n_flows) {
576 VLOG_WARN_RL(&error_rl, "dp%u: datapath stats reported %"PRIu32" "
577 "flows but flow listing reported %zu",
578 dpif->minor, stats.n_flows, n_flows);
586 dpif_execute(struct dpif *dpif, uint16_t in_port,
587 const union odp_action actions[], size_t n_actions,
588 const struct ofpbuf *buf)
592 COVERAGE_INC(dpif_execute);
594 struct odp_execute execute;
595 memset(&execute, 0, sizeof execute);
596 execute.in_port = in_port;
597 execute.actions = (union odp_action *) actions;
598 execute.n_actions = n_actions;
599 execute.data = buf->data;
600 execute.length = buf->size;
601 error = do_ioctl(dpif, ODP_EXECUTE, NULL, &execute);
606 if (!(error ? VLOG_DROP_WARN(&error_rl) : VLOG_DROP_DBG(&dpmsg_rl))) {
607 struct ds ds = DS_EMPTY_INITIALIZER;
608 char *packet = ofp_packet_to_string(buf->data, buf->size, buf->size);
609 ds_put_format(&ds, "dp%u: execute ", dpif->minor);
610 format_odp_actions(&ds, actions, n_actions);
612 ds_put_format(&ds, " failed (%s)", strerror(error));
614 ds_put_format(&ds, " on packet %s", packet);
615 vlog(THIS_MODULE, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
623 dpif_recv(struct dpif *dpif, struct ofpbuf **bufp)
629 buf = ofpbuf_new(65536);
630 retval = read(dpif->fd, ofpbuf_tail(buf), ofpbuf_tailroom(buf));
633 if (error != EAGAIN) {
634 VLOG_WARN_RL(&error_rl, "dp%u: read failed: %s",
635 dpif->minor, strerror(error));
637 } else if (retval >= sizeof(struct odp_msg)) {
638 struct odp_msg *msg = buf->data;
639 if (msg->length <= retval) {
641 if (VLOG_IS_DBG_ENABLED()) {
642 void *payload = msg + 1;
643 size_t length = buf->size - sizeof *msg;
644 char *s = ofp_packet_to_string(payload, length, length);
645 VLOG_DBG_RL(&dpmsg_rl, "dp%u: received %s message of length "
646 "%zu on port %"PRIu16": %s", dpif->minor,
647 (msg->type == _ODPL_MISS_NR ? "miss"
648 : msg->type == _ODPL_ACTION_NR ? "action"
650 msg->length - sizeof(struct odp_msg),
655 COVERAGE_INC(dpif_recv);
658 VLOG_WARN_RL(&error_rl, "dp%u: discarding message truncated "
659 "from %zu bytes to %d",
660 dpif->minor, msg->length, retval);
663 } else if (!retval) {
664 VLOG_WARN_RL(&error_rl, "dp%u: unexpected end of file", dpif->minor);
667 VLOG_WARN_RL(&error_rl,
668 "dp%u: discarding too-short message (%d bytes)",
669 dpif->minor, retval);
679 dpif_recv_wait(struct dpif *dpif)
681 poll_fd_wait(dpif->fd, POLLIN);
685 dpif_get_netflow_ids(const struct dpif *dpif,
686 uint8_t *engine_type, uint8_t *engine_id)
688 *engine_type = *engine_id = dpif->minor;
693 struct nl_sock *sock;
698 dpifmon_create(const char *datapath_name, struct dpifmon **monp)
701 char local_name[IFNAMSIZ];
704 mon = *monp = xmalloc(sizeof *mon);
706 error = dpif_open(datapath_name, &mon->dpif);
710 error = dpif_port_get_name(&mon->dpif, ODPP_LOCAL,
711 local_name, sizeof local_name);
713 goto error_close_dpif;
716 mon->local_ifindex = if_nametoindex(local_name);
717 if (!mon->local_ifindex) {
719 VLOG_WARN("could not get ifindex of %s device: %s",
720 local_name, strerror(errno));
721 goto error_close_dpif;
724 error = nl_sock_create(NETLINK_ROUTE, RTNLGRP_LINK, 0, 0, &mon->sock);
726 VLOG_WARN("could not create rtnetlink socket: %s", strerror(error));
727 goto error_close_dpif;
733 dpif_close(&mon->dpif);
741 dpifmon_destroy(struct dpifmon *mon)
744 dpif_close(&mon->dpif);
745 nl_sock_destroy(mon->sock);
750 dpifmon_poll(struct dpifmon *mon, char **devnamep)
752 static struct vlog_rate_limit slow_rl = VLOG_RATE_LIMIT_INIT(1, 5);
753 static const struct nl_policy rtnlgrp_link_policy[] = {
754 [IFLA_IFNAME] = { .type = NL_A_STRING },
755 [IFLA_MASTER] = { .type = NL_A_U32, .optional = true },
757 struct nlattr *attrs[ARRAY_SIZE(rtnlgrp_link_policy)];
763 error = nl_sock_recv(mon->sock, &buf, false);
766 if (!nl_policy_parse(buf, NLMSG_HDRLEN + sizeof(struct ifinfomsg),
768 attrs, ARRAY_SIZE(rtnlgrp_link_policy))) {
769 VLOG_WARN_RL(&slow_rl, "received bad rtnl message");
772 const char *devname = nl_attr_get_string(attrs[IFLA_IFNAME]);
775 if (attrs[IFLA_MASTER]) {
776 uint32_t master_ifindex = nl_attr_get_u32(attrs[IFLA_MASTER]);
777 for_us = master_ifindex == mon->local_ifindex;
779 /* It's for us if that device is one of our ports. This is
780 * open-coded instead of using dpif_port_query_by_name() to
781 * avoid logging a warning on failure. */
782 struct odp_port port;
783 memset(&port, 0, sizeof port);
784 strncpy(port.devname, devname, sizeof port.devname);
785 for_us = !ioctl(mon->dpif.fd, ODP_PORT_QUERY, &port);
789 /* Not for us, try again. */
791 COVERAGE_INC(dpifmon_poll_false_wakeup);
794 COVERAGE_INC(dpifmon_poll_changed);
795 *devnamep = xstrdup(devname);
805 VLOG_WARN_RL(&slow_rl, "dpifmon socket overflowed");
809 VLOG_WARN_RL(&slow_rl, "error on dpifmon socket: %s", strerror(error));
816 dpifmon_run(struct dpifmon *mon UNUSED)
818 /* Nothing to do in this implementation. */
822 dpifmon_wait(struct dpifmon *mon)
824 nl_sock_wait(mon->sock, POLLIN);
827 static int get_openvswitch_major(void);
828 static int get_major(const char *target, int default_major);
831 lookup_minor(const char *name, unsigned int *minor)
833 struct ethtool_drvinfo drvinfo;
839 sock = socket(AF_INET, SOCK_DGRAM, 0);
841 VLOG_WARN("socket(AF_INET) failed: %s", strerror(errno));
846 memset(&ifr, 0, sizeof ifr);
847 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
848 ifr.ifr_data = (caddr_t) &drvinfo;
850 memset(&drvinfo, 0, sizeof drvinfo);
851 drvinfo.cmd = ETHTOOL_GDRVINFO;
852 if (ioctl(sock, SIOCETHTOOL, &ifr)) {
853 VLOG_WARN("ioctl(SIOCETHTOOL) failed: %s", strerror(errno));
855 goto error_close_sock;
858 if (strcmp(drvinfo.driver, "openvswitch")) {
859 VLOG_WARN("%s is not an openvswitch device", name);
861 goto error_close_sock;
864 if (!isdigit(drvinfo.bus_info[0])) {
865 VLOG_WARN("%s ethtool info does not contain an openvswitch minor",
868 goto error_close_sock;
871 *minor = atoi(drvinfo.bus_info);
882 make_openvswitch_device(unsigned int minor, char **fnp)
884 dev_t dev = makedev(get_openvswitch_major(), minor);
885 const char dirname[] = "/dev/net";
890 sprintf(fn, "%s/dp%d", dirname, minor);
892 if (!S_ISCHR(s.st_mode)) {
893 VLOG_WARN_RL(&error_rl, "%s is not a character device, fixing",
895 } else if (s.st_rdev != dev) {
896 VLOG_WARN_RL(&error_rl,
897 "%s is device %u:%u instead of %u:%u, fixing",
898 fn, major(s.st_rdev), minor(s.st_rdev),
899 major(dev), minor(dev));
904 VLOG_WARN_RL(&error_rl, "%s: unlink failed (%s)",
905 fn, strerror(errno));
908 } else if (errno == ENOENT) {
909 if (stat(dirname, &s)) {
910 if (errno == ENOENT) {
911 if (mkdir(dirname, 0755)) {
912 VLOG_WARN_RL(&error_rl, "%s: mkdir failed (%s)",
913 dirname, strerror(errno));
917 VLOG_WARN_RL(&error_rl, "%s: stat failed (%s)",
918 dirname, strerror(errno));
923 VLOG_WARN_RL(&error_rl, "%s: stat failed (%s)", fn, strerror(errno));
927 /* The device needs to be created. */
928 if (mknod(fn, S_IFCHR | 0700, dev)) {
929 VLOG_WARN_RL(&error_rl,
930 "%s: creating character device %u:%u failed (%s)",
931 fn, major(dev), minor(dev), strerror(errno));
942 get_openvswitch_major(void)
944 static unsigned int openvswitch_major;
945 if (!openvswitch_major) {
946 enum { DEFAULT_MAJOR = 248 };
947 openvswitch_major = get_major("openvswitch", DEFAULT_MAJOR);
949 return openvswitch_major;
953 get_major(const char *target, int default_major)
955 const char fn[] = "/proc/devices";
960 file = fopen(fn, "r");
962 VLOG_ERR("opening %s failed (%s)", fn, strerror(errno));
966 for (ln = 1; fgets(line, sizeof line, file); ln++) {
970 if (!strncmp(line, "Character", 9) || line[0] == '\0') {
972 } else if (!strncmp(line, "Block", 5)) {
973 /* We only want character devices, so skip the rest of the file. */
975 } else if (sscanf(line, "%d %63s", &major, name)) {
976 if (!strcmp(name, target)) {
983 VLOG_WARN("%s:%d: syntax error", fn, ln);
989 VLOG_ERR("%s: %s major not found (is the module loaded?), using "
990 "default major %d", fn, target, default_major);
992 VLOG_INFO("using default major %d for %s", default_major, target);
993 return default_major;
997 name_to_minor(const char *name, unsigned int *minor)
999 if (!get_minor_from_name(name, minor)) {
1002 return lookup_minor(name, minor);
1006 get_minor_from_name(const char *name, unsigned int *minor)
1008 if (!strncmp(name, "dp", 2) && isdigit(name[2])) {
1009 *minor = atoi(name + 2);
1011 } else if (!strncmp(name, "nl:", 3) && isdigit(name[3])) {
1012 /* This is for compatibility only and will be dropped. */
1013 *minor = atoi(name + 3);
1021 open_by_minor(unsigned int minor, struct dpif *dpif)
1029 error = make_openvswitch_device(minor, &fn);
1034 fd = open(fn, O_RDONLY | O_NONBLOCK);
1037 VLOG_WARN("%s: open failed (%s)", fn, strerror(error));
1043 dpif->minor = minor;
1048 /* There is a tendency to construct odp_flow objects on the stack and to
1049 * forget to properly initialize their "actions" and "n_actions" members.
1050 * When this happens, we get memory corruption because the kernel
1051 * writes through the random pointer that is in the "actions" member.
1053 * This function attempts to combat the problem by:
1055 * - Forcing a segfault if "actions" points to an invalid region (instead
1056 * of just getting back EFAULT, which can be easily missed in the log).
1058 * - Storing a distinctive value that is likely to cause an
1059 * easy-to-identify error later if it is dereferenced, etc.
1061 * - Triggering a warning on uninitialized memory from Valgrind if
1062 * "actions" or "n_actions" was not initialized.
1065 check_rw_odp_flow(struct odp_flow *flow)
1067 if (flow->n_actions) {
1068 memset(&flow->actions[0], 0xcc, sizeof flow->actions[0]);