projects
/
project
/
netifd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
ec286d4
)
remove some more code duplication
author
Felix Fietkau
<nbd@openwrt.org>
Sun, 23 Oct 2011 14:02:18 +0000
(16:02 +0200)
committer
Felix Fietkau
<nbd@openwrt.org>
Sun, 23 Oct 2011 14:02:18 +0000
(16:02 +0200)
system-linux.c
patch
|
blob
|
history
diff --git
a/system-linux.c
b/system-linux.c
index
11126fa
..
0308e6f
100644
(file)
--- a/
system-linux.c
+++ b/
system-linux.c
@@
-42,6
+42,21
@@
handler_nl_event(struct uloop_fd *u, unsigned int events)
nl_recvmsgs(ev->sock, ev->cb);
}
nl_recvmsgs(ev->sock, ev->cb);
}
+static struct nl_sock *
+create_socket(int protocol)
+{
+ struct nl_sock *sock;
+
+ sock = nl_socket_alloc();
+ if (!sock)
+ return NULL;
+
+ if (nl_connect(sock, protocol))
+ return NULL;
+
+ return sock;
+}
+
static bool
create_event_socket(struct event_socket *ev, int protocol,
int (*cb)(struct nl_msg *msg, void *arg))
static bool
create_event_socket(struct event_socket *ev, int protocol,
int (*cb)(struct nl_msg *msg, void *arg))
@@
-53,13
+68,10
@@
create_event_socket(struct event_socket *ev, int protocol,
nl_cb_set(ev->cb, NL_CB_VALID, NL_CB_CUSTOM, cb, NULL);
nl_cb_set(ev->cb, NL_CB_VALID, NL_CB_CUSTOM, cb, NULL);
- ev->sock =
nl_socket_alloc(
);
+ ev->sock =
create_socket(protocol
);
if (!ev->sock)
return false;
if (!ev->sock)
return false;
- if (nl_connect(ev->sock, protocol))
- return false;
-
ev->uloop.fd = nl_socket_get_fd(ev->sock);
ev->uloop.cb = handler_nl_event;
uloop_fd_add(&ev->uloop, ULOOP_READ | ULOOP_EDGE_TRIGGER);
ev->uloop.fd = nl_socket_get_fd(ev->sock);
ev->uloop.cb = handler_nl_event;
uloop_fd_add(&ev->uloop, ULOOP_READ | ULOOP_EDGE_TRIGGER);
@@
-74,20
+86,16
@@
int system_init(void)
fcntl(sock_ioctl, F_SETFD, fcntl(sock_ioctl, F_GETFD) | FD_CLOEXEC);
// Prepare socket for routing / address control
fcntl(sock_ioctl, F_SETFD, fcntl(sock_ioctl, F_GETFD) | FD_CLOEXEC);
// Prepare socket for routing / address control
- sock_rtnl =
nl_socket_alloc(
);
+ sock_rtnl =
create_socket(NETLINK_ROUTE
);
if (!sock_rtnl)
return -1;
if (!sock_rtnl)
return -1;
- if (nl_connect(sock_rtnl, NETLINK_ROUTE))
- return -1;
-
if (!create_event_socket(&rtnl_event, NETLINK_ROUTE, cb_rtnl_event))
return -1;
// Receive network link events form kernel
nl_socket_add_membership(rtnl_event.sock, RTNLGRP_LINK);
if (!create_event_socket(&rtnl_event, NETLINK_ROUTE, cb_rtnl_event))
return -1;
// Receive network link events form kernel
nl_socket_add_membership(rtnl_event.sock, RTNLGRP_LINK);
-
return 0;
}
return 0;
}