diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-11-17 13:07:41 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-11-17 13:07:41 +0000 |
commit | 51977773c39d5034eb12b29be03e1ed42176b8e5 (patch) | |
tree | 3c9c3e0c8078dca08a82b2722d934dec91833e49 /src/nat/nat.c | |
parent | 45a5959e0880e2ac07fac765ba0284ef45414f91 (diff) | |
download | gnunet-51977773c39d5034eb12b29be03e1ed42176b8e5.tar.gz gnunet-51977773c39d5034eb12b29be03e1ed42176b8e5.zip |
-fixing memory leaks and shutdown issues related to NAT
Diffstat (limited to 'src/nat/nat.c')
-rw-r--r-- | src/nat/nat.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c index 200636e97..a2c1d4ac4 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -804,6 +804,7 @@ process_interfaces (void *cls, | |||
804 | GNUNET_free (tun_if); | 804 | GNUNET_free (tun_if); |
805 | return GNUNET_OK; | 805 | return GNUNET_OK; |
806 | } | 806 | } |
807 | GNUNET_free (tun_if); | ||
807 | } | 808 | } |
808 | /* skip virtual interfaces created by GNUnet-dns */ | 809 | /* skip virtual interfaces created by GNUnet-dns */ |
809 | if (GNUNET_OK == | 810 | if (GNUNET_OK == |
@@ -819,6 +820,7 @@ process_interfaces (void *cls, | |||
819 | GNUNET_free (tun_if); | 820 | GNUNET_free (tun_if); |
820 | return GNUNET_OK; | 821 | return GNUNET_OK; |
821 | } | 822 | } |
823 | GNUNET_free (tun_if); | ||
822 | } | 824 | } |
823 | /* skip virtual interfaces created by GNUnet-exit */ | 825 | /* skip virtual interfaces created by GNUnet-exit */ |
824 | if (GNUNET_OK == | 826 | if (GNUNET_OK == |
@@ -834,9 +836,9 @@ process_interfaces (void *cls, | |||
834 | GNUNET_free (tun_if); | 836 | GNUNET_free (tun_if); |
835 | return GNUNET_OK; | 837 | return GNUNET_OK; |
836 | } | 838 | } |
839 | GNUNET_free (tun_if); | ||
837 | } | 840 | } |
838 | 841 | ||
839 | |||
840 | switch (addr->sa_family) | 842 | switch (addr->sa_family) |
841 | { | 843 | { |
842 | case AF_INET: | 844 | case AF_INET: |
@@ -1127,15 +1129,23 @@ stun_request_callback (void *cls, | |||
1127 | struct GNUNET_NAT_Handle *h = cls; | 1129 | struct GNUNET_NAT_Handle *h = cls; |
1128 | 1130 | ||
1129 | h->stun_request = NULL; | 1131 | h->stun_request = NULL; |
1130 | if (GNUNET_NAT_ERROR_SUCCESS != result) | 1132 | switch (result) |
1131 | { | 1133 | { |
1134 | case GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR: | ||
1132 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1135 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1133 | "Error processing a STUN request: %d\n", | 1136 | "Failed to transmit STUN request\n"); |
1134 | result); | 1137 | break; |
1135 | } | 1138 | case GNUNET_NAT_ERROR_NOT_ONLINE: |
1136 | else | 1139 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1137 | { | 1140 | "Failed to resolve STUN server (are we online?)\n"); |
1141 | break; | ||
1142 | case GNUNET_NAT_ERROR_SUCCESS: | ||
1143 | /* all good, STUN request active */ | ||
1138 | h->waiting_stun = GNUNET_YES; | 1144 | h->waiting_stun = GNUNET_YES; |
1145 | break; | ||
1146 | default: | ||
1147 | /* unexpected error code for STUN */ | ||
1148 | GNUNET_break (0); | ||
1139 | } | 1149 | } |
1140 | } | 1150 | } |
1141 | 1151 | ||
@@ -1171,7 +1181,7 @@ GNUNET_NAT_is_valid_stun_packet (void *cls, | |||
1171 | 0, | 1181 | 0, |
1172 | sizeof(struct sockaddr_in)); | 1182 | sizeof(struct sockaddr_in)); |
1173 | 1183 | ||
1174 | /*Lets handle the packet*/ | 1184 | /* Lets handle the packet*/ |
1175 | if (GNUNET_NO == | 1185 | if (GNUNET_NO == |
1176 | GNUNET_NAT_stun_handle_packet (data, | 1186 | GNUNET_NAT_stun_handle_packet (data, |
1177 | len, | 1187 | len, |
@@ -1638,39 +1648,38 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1638 | { | 1648 | { |
1639 | char *stun_servers; | 1649 | char *stun_servers; |
1640 | size_t urls; | 1650 | size_t urls; |
1641 | int pos; | 1651 | ssize_t pos; |
1642 | size_t pos_port; | 1652 | size_t pos_port; |
1643 | 1653 | ||
1644 | h->socket = sock; | 1654 | h->socket = sock; |
1645 | h->actual_stun_server = NULL; | 1655 | h->actual_stun_server = NULL; |
1656 | stun_servers = NULL; | ||
1646 | /* Lets process the servers*/ | 1657 | /* Lets process the servers*/ |
1647 | if (GNUNET_OK != | 1658 | (void) GNUNET_CONFIGURATION_get_value_string (cfg, |
1648 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1659 | "nat", |
1649 | "nat", | 1660 | "STUN_SERVERS", |
1650 | "STUN_SERVERS", | 1661 | &stun_servers); |
1651 | &stun_servers)) | ||
1652 | { | ||
1653 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | ||
1654 | "nat", | ||
1655 | "STUN_SERVERS"); | ||
1656 | } | ||
1657 | |||
1658 | urls = 0; | 1662 | urls = 0; |
1659 | h->stun_servers_head = NULL; | 1663 | h->stun_servers_head = NULL; |
1660 | h->stun_servers_tail = NULL; | 1664 | h->stun_servers_tail = NULL; |
1661 | h->actual_stun_server = NULL; | 1665 | h->actual_stun_server = NULL; |
1662 | if (strlen (stun_servers) > 0) | 1666 | if ( (NULL != stun_servers) && |
1667 | (strlen (stun_servers) > 0) ) | ||
1663 | { | 1668 | { |
1664 | pos = strlen (stun_servers) - 1; | ||
1665 | pos_port = 0; | 1669 | pos_port = 0; |
1666 | while (pos >= 0) | 1670 | for (pos = strlen (stun_servers) - 1; |
1671 | pos >= 0; | ||
1672 | pos--) | ||
1667 | { | 1673 | { |
1668 | if (stun_servers[pos] == ':') | 1674 | if (stun_servers[pos] == ':') |
1669 | { | 1675 | { |
1670 | pos_port = pos + 1; | 1676 | pos_port = pos + 1; |
1677 | stun_servers[pos] = '\0'; | ||
1678 | continue; | ||
1671 | } | 1679 | } |
1672 | if ((stun_servers[pos] == ' ') || (0 == pos)) | 1680 | if ((stun_servers[pos] == ' ') || (0 == pos)) |
1673 | { | 1681 | { |
1682 | struct StunServerList *ml; | ||
1674 | 1683 | ||
1675 | /*Check if we do have a port*/ | 1684 | /*Check if we do have a port*/ |
1676 | if((0 == pos_port) || (pos_port <= pos)) | 1685 | if((0 == pos_port) || (pos_port <= pos)) |
@@ -1679,40 +1688,30 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1679 | "STUN server format mistake\n"); | 1688 | "STUN server format mistake\n"); |
1680 | break; | 1689 | break; |
1681 | } | 1690 | } |
1682 | |||
1683 | urls++; | 1691 | urls++; |
1684 | 1692 | ml = GNUNET_new (struct StunServerList); | |
1685 | struct StunServerList* ml = GNUNET_new (struct StunServerList); | ||
1686 | |||
1687 | ml->port = atoi (&stun_servers[pos_port]); | 1693 | ml->port = atoi (&stun_servers[pos_port]); |
1688 | stun_servers[pos_port-1] = '\0'; | ||
1689 | 1694 | ||
1690 | /* Remove trailing space */ | 1695 | /* Remove trailing space */ |
1691 | if(stun_servers[pos] == ' ') | 1696 | if(stun_servers[pos] == ' ') |
1692 | ml->address = GNUNET_strdup (&stun_servers[pos + 1]); | 1697 | ml->address = GNUNET_strdup (&stun_servers[pos + 1]); |
1693 | else | 1698 | else |
1694 | ml->address = GNUNET_strdup (&stun_servers[pos]); | 1699 | ml->address = GNUNET_strdup (&stun_servers[pos]); |
1695 | |||
1696 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1700 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1697 | "Found STUN server %s:%i\n", | 1701 | "Found STUN server %s:%i\n", |
1698 | ml->address, | 1702 | ml->address, |
1699 | ml->port); | 1703 | ml->port); |
1700 | |||
1701 | GNUNET_CONTAINER_DLL_insert (h->stun_servers_head, | 1704 | GNUNET_CONTAINER_DLL_insert (h->stun_servers_head, |
1702 | h->stun_servers_tail, | 1705 | h->stun_servers_tail, |
1703 | ml); | 1706 | ml); |
1704 | /* Make sure that we STOP if is the last one*/ | ||
1705 | if (0 == pos) | ||
1706 | break; | ||
1707 | } | 1707 | } |
1708 | |||
1709 | pos--; | ||
1710 | } | 1708 | } |
1711 | } | 1709 | } |
1712 | if (urls == 0) | 1710 | if (0 == urls) |
1713 | { | 1711 | { |
1714 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | 1712 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, |
1715 | "nat", "STUN_SERVERS"); | 1713 | "nat", |
1714 | "STUN_SERVERS"); | ||
1716 | } | 1715 | } |
1717 | else | 1716 | else |
1718 | { | 1717 | { |
@@ -1721,6 +1720,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1721 | } | 1720 | } |
1722 | h->stun_task = GNUNET_SCHEDULER_add_now (&process_stun, | 1721 | h->stun_task = GNUNET_SCHEDULER_add_now (&process_stun, |
1723 | h); | 1722 | h); |
1723 | GNUNET_free_non_null (stun_servers); | ||
1724 | } | 1724 | } |
1725 | 1725 | ||
1726 | 1726 | ||