Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From b5fd5945886fa1845db5c969424b63d894fe0376 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jian Liang <jianliang@tycoint.com> |
| 3 | Date: Fri, 25 Aug 2017 10:02:16 -0400 |
| 4 | Subject: [PATCH 1/2] session: Keep track of addr in fw_snat & session |
| 5 | To: connman@lists.01.org |
| 6 | Cc: wagi@monom.org |
| 7 | |
| 8 | When there is more than one session in fw_snat's list of sessions, |
| 9 | fw_snat failed to be re-created when update-session-state is triggered |
| 10 | with new IP address. This is because index alone is not sufficient to |
| 11 | decide if fw_snat needs to be re-created. The solution here is to keep |
| 12 | a track of IP addr and use it to avoid false lookup of fw_snat. |
| 13 | |
| 14 | Signed-off-by: Jian Liang <jianliang@tycoint.com> |
| 15 | |
| 16 | --- |
| 17 | Upstream-Status: Backport [https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=f9e27d4abfcab5c80a38e0850b5ddb26277f97c1] |
| 18 | Signed-off-by: André Draszik <andre.draszik@jci.com> |
| 19 | src/session.c | 19 +++++++++++++++---- |
| 20 | 1 file changed, 15 insertions(+), 4 deletions(-) |
| 21 | |
| 22 | diff --git a/src/session.c b/src/session.c |
| 23 | index 9e3c559..965ac06 100644 |
| 24 | --- a/src/session.c |
| 25 | +++ b/src/session.c |
| 26 | @@ -65,6 +65,7 @@ struct connman_session { |
| 27 | struct firewall_context *fw; |
| 28 | uint32_t mark; |
| 29 | int index; |
| 30 | + char *addr; |
| 31 | char *gateway; |
| 32 | bool policy_routing; |
| 33 | bool snat_enabled; |
| 34 | @@ -79,6 +80,7 @@ struct fw_snat { |
| 35 | GSList *sessions; |
| 36 | int id; |
| 37 | int index; |
| 38 | + char *addr; |
| 39 | struct firewall_context *fw; |
| 40 | }; |
| 41 | |
| 42 | @@ -200,7 +202,7 @@ static char *service2bearer(enum connman_service_type type) |
| 43 | return ""; |
| 44 | } |
| 45 | |
| 46 | -static struct fw_snat *fw_snat_lookup(int index) |
| 47 | +static struct fw_snat *fw_snat_lookup(int index, const char *addr) |
| 48 | { |
| 49 | struct fw_snat *fw_snat; |
| 50 | GSList *list; |
| 51 | @@ -208,8 +210,11 @@ static struct fw_snat *fw_snat_lookup(int index) |
| 52 | for (list = fw_snat_list; list; list = list->next) { |
| 53 | fw_snat = list->data; |
| 54 | |
| 55 | - if (fw_snat->index == index) |
| 56 | + if (fw_snat->index == index) { |
| 57 | + if (g_strcmp0(addr, fw_snat->addr) != 0) |
| 58 | + continue; |
| 59 | return fw_snat; |
| 60 | + } |
| 61 | } |
| 62 | return NULL; |
| 63 | } |
| 64 | @@ -224,6 +229,7 @@ static int fw_snat_create(struct connman_session *session, |
| 65 | |
| 66 | fw_snat->fw = __connman_firewall_create(); |
| 67 | fw_snat->index = index; |
| 68 | + fw_snat->addr = g_strdup(addr); |
| 69 | |
| 70 | fw_snat->id = __connman_firewall_enable_snat(fw_snat->fw, |
| 71 | index, ifname, addr); |
| 72 | @@ -238,6 +244,7 @@ static int fw_snat_create(struct connman_session *session, |
| 73 | return 0; |
| 74 | err: |
| 75 | __connman_firewall_destroy(fw_snat->fw); |
| 76 | + g_free(fw_snat->addr); |
| 77 | g_free(fw_snat); |
| 78 | return err; |
| 79 | } |
| 80 | @@ -393,7 +400,7 @@ static void del_nat_rules(struct connman_session *session) |
| 81 | return; |
| 82 | |
| 83 | session->snat_enabled = false; |
| 84 | - fw_snat = fw_snat_lookup(session->index); |
| 85 | + fw_snat = fw_snat_lookup(session->index, session->addr); |
| 86 | |
| 87 | if (!fw_snat) |
| 88 | return; |
| 89 | @@ -420,8 +427,11 @@ static void add_nat_rules(struct connman_session *session) |
| 90 | if (!addr) |
| 91 | return; |
| 92 | |
| 93 | + g_free(session->addr); |
| 94 | + session->addr = g_strdup(addr); |
| 95 | + |
| 96 | session->snat_enabled = true; |
| 97 | - fw_snat = fw_snat_lookup(index); |
| 98 | + fw_snat = fw_snat_lookup(index, session->addr); |
| 99 | if (fw_snat) { |
| 100 | fw_snat_ref(session, fw_snat); |
| 101 | return; |
| 102 | @@ -502,6 +512,7 @@ static void free_session(struct connman_session *session) |
| 103 | g_free(session->info); |
| 104 | g_free(session->info_last); |
| 105 | g_free(session->gateway); |
| 106 | + g_free(session->addr); |
| 107 | |
| 108 | g_free(session); |
| 109 | } |
| 110 | -- |
| 111 | 2.7.4 |
| 112 | |