- static bool inited;
- if (!inited) {
- int ifindex;
- int error;
-
- inited = true;
-
- fatal_signal_add_hook(restore_all_flags, NULL, true);
-
- af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (af_inet_sock < 0) {
- ovs_fatal(errno, "socket(AF_INET)");
- }
-
- error = nl_sock_create(NETLINK_ROUTE, 0, 0, 0, &rtnl_sock);
- if (error) {
- ovs_fatal(error, "socket(AF_NETLINK, NETLINK_ROUTE)");
- }
-
- /* Decide on the netdev_get_stats() implementation to use. Netlink is
- * preferable, so if that works, we'll use it. */
- ifindex = do_get_ifindex("lo");
- if (ifindex < 0) {
- VLOG_WARN("failed to get ifindex for lo, "
- "obtaining netdev stats from proc");
- use_netlink_stats = false;
- } else {
- struct netdev_stats stats;
- error = get_stats_via_netlink(ifindex, &stats);
- if (!error) {
- VLOG_DBG("obtaining netdev stats via rtnetlink");
- use_netlink_stats = true;
- } else {
- VLOG_INFO("RTM_GETLINK failed (%s), obtaining netdev stats "
- "via proc (you are probably running a pre-2.6.19 "
- "kernel)", strerror(error));
- use_netlink_stats = false;
- }
- }
- }