]> code.ossystems Code Review - openembedded-core.git/blob
9c953e5d5111263589ee0d2cf93643de6808d76d
[openembedded-core.git] /
1 From 08cda4004491d3971a8b9df937426c43800d15b1 Mon Sep 17 00:00:00 2001
2 From: Jian Liang <jianliang@tycoint.com>
3 Date: Thu, 5 Oct 2017 09:37:06 +0100
4 Subject: [PATCH 2/4] inet: Implement subnet route creation/deletion in
5  iproute_default_modify
6 To: connman@lists.01.org
7 Cc: wagi@monom.org
8
9 - Calculate subnet address base on gateway address and prefixlen
10 - Differentiate creation of routes to gateway and subnet
11
12 Signed-off-by: Jian Liang <jianliang@tycoint.com>
13
14 ---
15 Upstream-Status: Backport [https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=ff7dcf91f12a2a237feebc6e606d0a8e92975528]
16 Signed-off-by: AndrĂ© Draszik <andre.draszik@jci.com>
17  src/inet.c | 22 +++++++++++++++++++---
18  1 file changed, 19 insertions(+), 3 deletions(-)
19
20 diff --git a/src/inet.c b/src/inet.c
21 index ab8aec8..0ddb030 100644
22 --- a/src/inet.c
23 +++ b/src/inet.c
24 @@ -2802,6 +2802,9 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
25         unsigned char buf[sizeof(struct in6_addr)];
26         int ret, len;
27         int family = connman_inet_check_ipaddress(gateway);
28 +       char *dst = NULL;
29 +
30 +       DBG("gateway %s/%u table %u", gateway, prefixlen, table_id);
31  
32         switch (family) {
33         case AF_INET:
34 @@ -2814,7 +2817,19 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
35                 return -EINVAL;
36         }
37  
38 -       ret = inet_pton(family, gateway, buf);
39 +       if (prefixlen) {
40 +               struct in_addr ipv4_subnet_addr, ipv4_mask;
41 +
42 +               memset(&ipv4_subnet_addr, 0, sizeof(ipv4_subnet_addr));
43 +               ipv4_mask.s_addr = htonl((0xffffffff << (32 - prefixlen)) & 0xffffffff);
44 +               ipv4_subnet_addr.s_addr = inet_addr(gateway);
45 +               ipv4_subnet_addr.s_addr &= ipv4_mask.s_addr;
46 +
47 +               dst = g_strdup(inet_ntoa(ipv4_subnet_addr));
48 +       }
49 +
50 +       ret = inet_pton(family, dst ? dst : gateway, buf);
51 +       g_free(dst);
52         if (ret <= 0)
53                 return -EINVAL;
54  
55 @@ -2831,8 +2846,9 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
56         rth.req.u.r.rt.rtm_type = RTN_UNICAST;
57         rth.req.u.r.rt.rtm_dst_len = prefixlen;
58  
59 -       __connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), RTA_GATEWAY,
60 -                                                               buf, len);
61 +       __connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req),
62 +               prefixlen > 0 ? RTA_DST : RTA_GATEWAY, buf, len);
63 +
64         if (table_id < 256) {
65                 rth.req.u.r.rt.rtm_table = table_id;
66         } else {
67 -- 
68 2.7.4
69