diff options
Diffstat (limited to 'src/nat/test_nat.c')
-rw-r--r-- | src/nat/test_nat.c | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/src/nat/test_nat.c b/src/nat/test_nat.c index 80d7cf792..5758f63b9 100644 --- a/src/nat/test_nat.c +++ b/src/nat/test_nat.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Testcase for port redirection and public IP address retrieval. | 22 | * Testcase for port redirection and public IP address retrieval. |
@@ -43,7 +43,7 @@ | |||
43 | /** | 43 | /** |
44 | * Time to wait before stopping NAT, in seconds | 44 | * Time to wait before stopping NAT, in seconds |
45 | */ | 45 | */ |
46 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 46 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) |
47 | 47 | ||
48 | 48 | ||
49 | /** | 49 | /** |
@@ -51,15 +51,15 @@ | |||
51 | * believes to be valid for the transport. | 51 | * believes to be valid for the transport. |
52 | */ | 52 | */ |
53 | static void | 53 | static void |
54 | addr_callback (void *cls, int add_remove, const struct sockaddr *addr, | 54 | addr_callback(void *cls, int add_remove, const struct sockaddr *addr, |
55 | socklen_t addrlen) | 55 | socklen_t addrlen) |
56 | { | 56 | { |
57 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 57 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
58 | "Address changed: %s `%s' (%u bytes)\n", | 58 | "Address changed: %s `%s' (%u bytes)\n", |
59 | add_remove == GNUNET_YES ? "added" : "removed", | 59 | add_remove == GNUNET_YES ? "added" : "removed", |
60 | GNUNET_a2s (addr, | 60 | GNUNET_a2s(addr, |
61 | addrlen), | 61 | addrlen), |
62 | (unsigned int) addrlen); | 62 | (unsigned int)addrlen); |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
@@ -67,18 +67,17 @@ addr_callback (void *cls, int add_remove, const struct sockaddr *addr, | |||
67 | * Function that terminates the test. | 67 | * Function that terminates the test. |
68 | */ | 68 | */ |
69 | static void | 69 | static void |
70 | stop (void *cls) | 70 | stop(void *cls) |
71 | { | 71 | { |
72 | struct GNUNET_NAT_Handle *nat = cls; | 72 | struct GNUNET_NAT_Handle *nat = cls; |
73 | 73 | ||
74 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 74 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
75 | "Stopping NAT and quitting...\n"); | 75 | "Stopping NAT and quitting...\n"); |
76 | GNUNET_NAT_unregister (nat); | 76 | GNUNET_NAT_unregister(nat); |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | struct addr_cls | 80 | struct addr_cls { |
81 | { | ||
82 | struct sockaddr *addr; | 81 | struct sockaddr *addr; |
83 | socklen_t addrlen; | 82 | socklen_t addrlen; |
84 | }; | 83 | }; |
@@ -96,21 +95,21 @@ struct addr_cls | |||
96 | * @return #GNUNET_OK to continue iterating | 95 | * @return #GNUNET_OK to continue iterating |
97 | */ | 96 | */ |
98 | static int | 97 | static int |
99 | process_if (void *cls, | 98 | process_if(void *cls, |
100 | const char *name, | 99 | const char *name, |
101 | int isDefault, | 100 | int isDefault, |
102 | const struct sockaddr *addr, | 101 | const struct sockaddr *addr, |
103 | const struct sockaddr *broadcast_addr, | 102 | const struct sockaddr *broadcast_addr, |
104 | const struct sockaddr *netmask, | 103 | const struct sockaddr *netmask, |
105 | socklen_t addrlen) | 104 | socklen_t addrlen) |
106 | { | 105 | { |
107 | struct addr_cls *data = cls; | 106 | struct addr_cls *data = cls; |
108 | 107 | ||
109 | if (addr == NULL) | 108 | if (addr == NULL) |
110 | return GNUNET_OK; | 109 | return GNUNET_OK; |
111 | GNUNET_free_non_null (data->addr); | 110 | GNUNET_free_non_null(data->addr); |
112 | data->addr = GNUNET_malloc (addrlen); | 111 | data->addr = GNUNET_malloc(addrlen); |
113 | GNUNET_memcpy (data->addr, addr, addrlen); | 112 | GNUNET_memcpy(data->addr, addr, addrlen); |
114 | data->addrlen = addrlen; | 113 | data->addrlen = addrlen; |
115 | if (isDefault) | 114 | if (isDefault) |
116 | return GNUNET_SYSERR; | 115 | return GNUNET_SYSERR; |
@@ -122,44 +121,44 @@ process_if (void *cls, | |||
122 | * Main function run with scheduler. | 121 | * Main function run with scheduler. |
123 | */ | 122 | */ |
124 | static void | 123 | static void |
125 | run (void *cls, | 124 | run(void *cls, |
126 | char *const *args, | 125 | char *const *args, |
127 | const char *cfgfile, | 126 | const char *cfgfile, |
128 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 127 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
129 | { | 128 | { |
130 | struct GNUNET_NAT_Handle *nat; | 129 | struct GNUNET_NAT_Handle *nat; |
131 | struct addr_cls data; | 130 | struct addr_cls data; |
132 | struct sockaddr *addr; | 131 | struct sockaddr *addr; |
133 | 132 | ||
134 | data.addr = NULL; | 133 | data.addr = NULL; |
135 | GNUNET_OS_network_interfaces_list (process_if, &data); | 134 | GNUNET_OS_network_interfaces_list(process_if, &data); |
136 | if (NULL == data.addr) | 135 | if (NULL == data.addr) |
137 | { | 136 | { |
138 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 137 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
139 | "Could not find a valid interface address!\n"); | 138 | "Could not find a valid interface address!\n"); |
140 | exit (77); /* marks test as skipped */ | 139 | exit(77); /* marks test as skipped */ |
141 | } | 140 | } |
142 | addr = data.addr; | 141 | addr = data.addr; |
143 | GNUNET_assert (addr->sa_family == AF_INET || addr->sa_family == AF_INET6); | 142 | GNUNET_assert(addr->sa_family == AF_INET || addr->sa_family == AF_INET6); |
144 | if (addr->sa_family == AF_INET) | 143 | if (addr->sa_family == AF_INET) |
145 | ((struct sockaddr_in *) addr)->sin_port = htons (2086); | 144 | ((struct sockaddr_in *)addr)->sin_port = htons(2086); |
146 | else | 145 | else |
147 | ((struct sockaddr_in6 *) addr)->sin6_port = htons (2086); | 146 | ((struct sockaddr_in6 *)addr)->sin6_port = htons(2086); |
148 | 147 | ||
149 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 148 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
150 | "Requesting NAT redirection from address %s...\n", | 149 | "Requesting NAT redirection from address %s...\n", |
151 | GNUNET_a2s (addr, data.addrlen)); | 150 | GNUNET_a2s(addr, data.addrlen)); |
152 | 151 | ||
153 | nat = GNUNET_NAT_register (cfg, GNUNET_YES /* tcp */ , | 152 | nat = GNUNET_NAT_register(cfg, GNUNET_YES /* tcp */, |
154 | 2086, 1, (const struct sockaddr **) &addr, | 153 | 2086, 1, (const struct sockaddr **)&addr, |
155 | &data.addrlen, &addr_callback, NULL, NULL, NULL); | 154 | &data.addrlen, &addr_callback, NULL, NULL, NULL); |
156 | GNUNET_free (addr); | 155 | GNUNET_free(addr); |
157 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &stop, nat); | 156 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &stop, nat); |
158 | } | 157 | } |
159 | 158 | ||
160 | 159 | ||
161 | int | 160 | int |
162 | main (int argc, char *const argv[]) | 161 | main(int argc, char *const argv[]) |
163 | { | 162 | { |
164 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 163 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
165 | GNUNET_GETOPT_OPTION_END | 164 | GNUNET_GETOPT_OPTION_END |
@@ -171,19 +170,20 @@ main (int argc, char *const argv[]) | |||
171 | "test_nat_data.conf", | 170 | "test_nat_data.conf", |
172 | NULL | 171 | NULL |
173 | }; | 172 | }; |
174 | GNUNET_log_setup ("test-nat", | 173 | |
175 | "WARNING", | 174 | GNUNET_log_setup("test-nat", |
176 | NULL); | 175 | "WARNING", |
177 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 176 | NULL); |
178 | "Testing NAT library, timeout set to %s\n", | 177 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
179 | GNUNET_STRINGS_relative_time_to_string (TIMEOUT, | 178 | "Testing NAT library, timeout set to %s\n", |
180 | GNUNET_YES)); | 179 | GNUNET_STRINGS_relative_time_to_string(TIMEOUT, |
181 | GNUNET_PROGRAM_run (3, | 180 | GNUNET_YES)); |
182 | argv_prog, | 181 | GNUNET_PROGRAM_run(3, |
183 | "test-nat", | 182 | argv_prog, |
184 | "nohelp", | 183 | "test-nat", |
185 | options, | 184 | "nohelp", |
186 | &run, NULL); | 185 | options, |
186 | &run, NULL); | ||
187 | return 0; | 187 | return 0; |
188 | } | 188 | } |
189 | 189 | ||