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
6 To: connman@lists.01.org
9 - Calculate subnet address base on gateway address and prefixlen
10 - Differentiate creation of routes to gateway and subnet
12 Signed-off-by: Jian Liang <jianliang@tycoint.com>
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(-)
20 diff --git a/src/inet.c b/src/inet.c
21 index ab8aec8..0ddb030 100644
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)];
27 int family = connman_inet_check_ipaddress(gateway);
30 + DBG("gateway %s/%u table %u", gateway, prefixlen, table_id);
34 @@ -2814,7 +2817,19 @@ static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
38 - ret = inet_pton(family, gateway, buf);
40 + struct in_addr ipv4_subnet_addr, ipv4_mask;
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;
47 + dst = g_strdup(inet_ntoa(ipv4_subnet_addr));
50 + ret = inet_pton(family, dst ? dst : gateway, buf);
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;
59 - __connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), RTA_GATEWAY,
61 + __connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req),
62 + prefixlen > 0 ? RTA_DST : RTA_GATEWAY, buf, len);
65 rth.req.u.r.rt.rtm_table = table_id;