summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-08-08 23:20:22 -0700
committerMarcel Holtmann <marcel@holtmann.org>2009-08-08 23:20:22 -0700
commit8b068ec0ab46809b4d7beafe3eaaa8eb1a74db75 (patch)
tree4bfd700ca025d861998446587d642cb64488c8d6
parentd84b70acae41e8a64fbc2577e9f7ebe3fd990698 (diff)
downloadconnman-8b068ec0ab46809b4d7beafe3eaaa8eb1a74db75.tar.gz
connman-8b068ec0ab46809b4d7beafe3eaaa8eb1a74db75.tar.bz2
connman-8b068ec0ab46809b4d7beafe3eaaa8eb1a74db75.zip
Optimize the RTNL routing table parsing
-rw-r--r--src/rtnl.c56
1 files changed, 14 insertions, 42 deletions
diff --git a/src/rtnl.c b/src/rtnl.c
index 785a1de6..b0366201 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -393,6 +393,16 @@ static void process_newroute(unsigned char family, unsigned char scope,
__connman_ipconfig_add_route(ipconfig, scope,
dststr, gatewaystr);
}
+
+ if (scope != RT_SCOPE_UNIVERSE || dst.s_addr != INADDR_ANY)
+ return;
+
+ for (list = rtnl_list; list; list = list->next) {
+ struct connman_rtnl *rtnl = list->data;
+
+ if (rtnl->newgateway)
+ rtnl->newgateway(index, gatewaystr);
+ }
}
static void process_delroute(unsigned char family, unsigned char scope,
@@ -420,43 +430,15 @@ static void process_delroute(unsigned char family, unsigned char scope,
__connman_ipconfig_del_route(ipconfig, scope,
dststr, gatewaystr);
}
-}
-
-static void process_newgateway(struct rtmsg *msg, int bytes)
-{
- GSList *list;
- struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
- int index = -1;
-
- extract_route(msg, bytes, &index, &dst, &gateway);
-
- if (dst.s_addr != INADDR_ANY)
- return;
-
- for (list = rtnl_list; list; list = list->next) {
- struct connman_rtnl *rtnl = list->data;
-
- if (rtnl->newgateway)
- rtnl->newgateway(index, inet_ntoa(gateway));
- }
-}
-static void process_delgateway(struct rtmsg *msg, int bytes)
-{
- GSList *list;
- struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
- int index = -1;
-
- extract_route(msg, bytes, &index, &dst, &gateway);
-
- if (dst.s_addr != INADDR_ANY)
+ if (scope != RT_SCOPE_UNIVERSE || dst.s_addr != INADDR_ANY)
return;
for (list = rtnl_list; list; list = list->next) {
struct connman_rtnl *rtnl = list->data;
if (rtnl->delgateway)
- rtnl->delgateway(index, inet_ntoa(gateway));
+ rtnl->delgateway(index, gatewaystr);
}
}
@@ -712,14 +694,9 @@ static void rtnl_newroute(struct nlmsghdr *hdr)
if (msg->rtm_table == RT_TABLE_MAIN &&
msg->rtm_protocol == RTPROT_BOOT &&
- msg->rtm_type == RTN_UNICAST) {
-
+ msg->rtm_type == RTN_UNICAST)
process_newroute(msg->rtm_family, msg->rtm_scope,
msg, RTM_PAYLOAD(hdr));
-
- if (msg->rtm_scope == RT_SCOPE_UNIVERSE)
- process_newgateway(msg, RTM_PAYLOAD(hdr));
- }
}
static void rtnl_delroute(struct nlmsghdr *hdr)
@@ -730,14 +707,9 @@ static void rtnl_delroute(struct nlmsghdr *hdr)
if (msg->rtm_table == RT_TABLE_MAIN &&
msg->rtm_protocol == RTPROT_BOOT &&
- msg->rtm_type == RTN_UNICAST) {
-
+ msg->rtm_type == RTN_UNICAST)
process_delroute(msg->rtm_family, msg->rtm_scope,
msg, RTM_PAYLOAD(hdr));
-
- if (msg->rtm_scope == RT_SCOPE_UNIVERSE)
- process_delgateway(msg, RTM_PAYLOAD(hdr));
- }
}
static const char *type2string(uint16_t type)