mirror of
https://github.com/troglobit/finit.git
synced 2026-10-28 12:30:44 +00:00
netlink.so: Refactor, break out condition set/clear func.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
80a71aff07
commit
cf6faa9eeb
1 file changed
+18
-25
+18
-25
@@ -94,6 +94,17 @@ static void nl_route(struct nlmsghdr *nlmsg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void net_cond_set(char *ifname, char *cond, int set)
|
||||||
|
{
|
||||||
|
char msg[MAX_ARG_LEN];
|
||||||
|
|
||||||
|
snprintf(msg, sizeof(msg), "net/%s/%s", ifname, cond);
|
||||||
|
if (set)
|
||||||
|
cond_set(msg);
|
||||||
|
else
|
||||||
|
cond_clear(msg);
|
||||||
|
}
|
||||||
|
|
||||||
static void nl_link(struct nlmsghdr *nlmsg)
|
static void nl_link(struct nlmsghdr *nlmsg)
|
||||||
{
|
{
|
||||||
int la;
|
int la;
|
||||||
@@ -112,8 +123,6 @@ static void nl_link(struct nlmsghdr *nlmsg)
|
|||||||
|
|
||||||
while (RTA_OK(a, la)) {
|
while (RTA_OK(a, la)) {
|
||||||
if (a->rta_type == IFLA_IFNAME) {
|
if (a->rta_type == IFLA_IFNAME) {
|
||||||
char msg[MAX_ARG_LEN];
|
|
||||||
|
|
||||||
strlcpy(ifname, RTA_DATA(a), sizeof(ifname));
|
strlcpy(ifname, RTA_DATA(a), sizeof(ifname));
|
||||||
switch (nlmsg->nlmsg_type) {
|
switch (nlmsg->nlmsg_type) {
|
||||||
case RTM_NEWLINK:
|
case RTM_NEWLINK:
|
||||||
@@ -122,33 +131,17 @@ static void nl_link(struct nlmsghdr *nlmsg)
|
|||||||
* Check ifi_flags here to see if the interface is UP/DOWN
|
* Check ifi_flags here to see if the interface is UP/DOWN
|
||||||
*/
|
*/
|
||||||
_d("%s: New link, flags 0x%x, change 0x%x", ifname, i->ifi_flags, i->ifi_change);
|
_d("%s: New link, flags 0x%x, change 0x%x", ifname, i->ifi_flags, i->ifi_change);
|
||||||
snprintf(msg, sizeof(msg), "net/%s/exist", ifname);
|
net_cond_set(ifname, "exist", 1);
|
||||||
cond_set(msg);
|
net_cond_set(ifname, "up", i->ifi_flags & IFF_UP);
|
||||||
|
net_cond_set(ifname, "running", i->ifi_flags & IFF_RUNNING);
|
||||||
snprintf(msg, sizeof(msg), "net/%s/up", ifname);
|
|
||||||
if (i->ifi_flags & IFF_UP)
|
|
||||||
cond_set(msg);
|
|
||||||
else
|
|
||||||
cond_clear(msg);
|
|
||||||
|
|
||||||
snprintf(msg, sizeof(msg), "net/%s/running", ifname);
|
|
||||||
if (i->ifi_flags & IFF_RUNNING)
|
|
||||||
cond_set(msg);
|
|
||||||
else
|
|
||||||
cond_clear(msg);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RTM_DELLINK:
|
case RTM_DELLINK:
|
||||||
/* NOTE: Interface has disappeared, not link down ... */
|
/* NOTE: Interface has disappeared, not link down ... */
|
||||||
_e("%s: Delete link", ifname);
|
_d("%s: Delete link", ifname);
|
||||||
snprintf(msg, sizeof(msg), "net/%s/exist", ifname);
|
net_cond_set(ifname, "exist", 0);
|
||||||
cond_clear(msg);
|
net_cond_set(ifname, "up", 0);
|
||||||
|
net_cond_set(ifname, "running", 0);
|
||||||
snprintf(msg, sizeof(msg), "net/%s/up", ifname);
|
|
||||||
cond_clear(msg);
|
|
||||||
|
|
||||||
snprintf(msg, sizeof(msg), "net/%s/running", ifname);
|
|
||||||
cond_clear(msg);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RTM_NEWADDR:
|
case RTM_NEWADDR:
|
||||||
|
|||||||
Reference in new issue
Block a user