Yasuyuki KOZAKAI | 5208806 | 2007-07-24 05:44:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2000-2006 by the netfilter coreteam <coreteam@netfilter.org>: |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | */ |
| 18 | |
Yasuyuki KOZAKAI | 3dfa448 | 2007-07-24 05:45:33 +0000 | [diff] [blame] | 19 | #include <errno.h> |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 20 | #include <fcntl.h> |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 21 | #include <netdb.h> |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 22 | #include <stdarg.h> |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 23 | #include <stdbool.h> |
Yasuyuki KOZAKAI | 3dfa448 | 2007-07-24 05:45:33 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <unistd.h> |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 28 | #include <sys/socket.h> |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 29 | #include <sys/stat.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/wait.h> |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 32 | #include <arpa/inet.h> |
Yasuyuki KOZAKAI | 3dfa448 | 2007-07-24 05:45:33 +0000 | [diff] [blame] | 33 | |
Yasuyuki KOZAKAI | 5208806 | 2007-07-24 05:44:11 +0000 | [diff] [blame] | 34 | #include <xtables.h> |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 35 | #include <linux/netfilter_ipv4/ip_tables.h> |
| 36 | #include <linux/netfilter_ipv6/ip6_tables.h> |
Jan Engelhardt | ef18e81 | 2008-08-04 12:47:48 +0200 | [diff] [blame] | 37 | #include <libiptc/libxtc.h> |
Yasuyuki KOZAKAI | 3dfa448 | 2007-07-24 05:45:33 +0000 | [diff] [blame] | 38 | |
Mike Frysinger | 5a26b5f | 2007-12-19 14:51:17 +0000 | [diff] [blame] | 39 | #ifndef NO_SHARED_LIBS |
| 40 | #include <dlfcn.h> |
| 41 | #endif |
Jan Engelhardt | c31870f | 2009-02-10 10:48:28 +0100 | [diff] [blame] | 42 | #ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */ |
| 43 | # define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2) |
| 44 | # define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3) |
| 45 | #endif |
| 46 | #ifndef IP6T_SO_GET_REVISION_MATCH /* Old kernel source. */ |
| 47 | # define IP6T_SO_GET_REVISION_MATCH 68 |
| 48 | # define IP6T_SO_GET_REVISION_TARGET 69 |
| 49 | #endif |
Jamal Hadi Salim | 7058192 | 2009-02-13 08:36:44 -0500 | [diff] [blame] | 50 | #include <getopt.h> |
Jan Engelhardt | c31870f | 2009-02-10 10:48:28 +0100 | [diff] [blame] | 51 | |
Mike Frysinger | 5a26b5f | 2007-12-19 14:51:17 +0000 | [diff] [blame] | 52 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 53 | #define NPROTO 255 |
| 54 | |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 55 | #ifndef PROC_SYS_MODPROBE |
| 56 | #define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe" |
| 57 | #endif |
| 58 | |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 59 | void basic_exit_err(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3))); |
| 60 | |
Jamal Hadi Salim | 40a8343 | 2009-02-11 13:02:21 +0100 | [diff] [blame] | 61 | struct xtables_globals *xt_params = NULL; |
| 62 | |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 63 | void basic_exit_err(enum xtables_exittype status, const char *msg, ...) |
Jamal Hadi Salim | 40a8343 | 2009-02-11 13:02:21 +0100 | [diff] [blame] | 64 | { |
| 65 | va_list args; |
| 66 | |
| 67 | va_start(args, msg); |
| 68 | fprintf(stderr, "%s v%s: ", xt_params->program_name, xt_params->program_version); |
| 69 | vfprintf(stderr, msg, args); |
| 70 | va_end(args); |
| 71 | fprintf(stderr, "\n"); |
| 72 | exit(status); |
| 73 | } |
| 74 | |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 75 | |
Jamal Hadi Salim | 139b3fe | 2009-02-12 11:43:01 -0500 | [diff] [blame] | 76 | void xtables_free_opts(int reset_offset) |
Jamal Hadi Salim | 84c3055 | 2009-02-11 13:00:02 +0100 | [diff] [blame] | 77 | { |
Jamal Hadi Salim | 139b3fe | 2009-02-12 11:43:01 -0500 | [diff] [blame] | 78 | if (xt_params->opts != xt_params->orig_opts) { |
| 79 | free(xt_params->opts); |
| 80 | xt_params->opts = xt_params->orig_opts; |
Jamal Hadi Salim | 84c3055 | 2009-02-11 13:00:02 +0100 | [diff] [blame] | 81 | if (reset_offset) |
| 82 | xt_params->option_offset = 0; |
| 83 | } |
| 84 | } |
| 85 | |
Jamal Hadi Salim | 7058192 | 2009-02-13 08:36:44 -0500 | [diff] [blame] | 86 | struct option *xtables_merge_options(struct option *oldopts, |
| 87 | const struct option *newopts, |
| 88 | unsigned int *option_offset) |
| 89 | { |
| 90 | unsigned int num_old, num_new, i; |
| 91 | struct option *merge; |
| 92 | |
| 93 | if (newopts == NULL) |
| 94 | return oldopts; |
| 95 | |
| 96 | for (num_old = 0; oldopts[num_old].name; num_old++) ; |
| 97 | for (num_new = 0; newopts[num_new].name; num_new++) ; |
| 98 | |
| 99 | xt_params->option_offset += OPTION_OFFSET; |
| 100 | *option_offset = xt_params->option_offset; |
| 101 | |
| 102 | merge = malloc(sizeof(struct option) * (num_new + num_old + 1)); |
| 103 | if (merge == NULL) |
| 104 | return NULL; |
| 105 | memcpy(merge, oldopts, num_old * sizeof(struct option)); |
| 106 | xtables_free_opts(0); /* Release any old options merged */ |
| 107 | for (i = 0; i < num_new; i++) { |
| 108 | merge[num_old + i] = newopts[i]; |
| 109 | merge[num_old + i].val += *option_offset; |
| 110 | } |
| 111 | memset(merge + num_old + num_new, 0, sizeof(struct option)); |
| 112 | |
| 113 | return merge; |
| 114 | } |
| 115 | |
Jamal Hadi Salim | 8533221 | 2009-02-12 09:33:59 -0500 | [diff] [blame] | 116 | void xtables_set_revision(char *name, u_int8_t revision) |
| 117 | { |
| 118 | /* Old kernel sources don't have ".revision" field, |
| 119 | * but we stole a byte from name. */ |
| 120 | name[XT_FUNCTION_MAXNAMELEN - 2] = '\0'; |
| 121 | name[XT_FUNCTION_MAXNAMELEN - 1] = revision; |
| 122 | } |
| 123 | |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 124 | /** |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 125 | * xtables_afinfo - protocol family dependent information |
| 126 | * @kmod: kernel module basename (e.g. "ip_tables") |
| 127 | * @libprefix: prefix of .so library name (e.g. "libipt_") |
| 128 | * @family: nfproto family |
| 129 | * @ipproto: used by setsockopt (e.g. IPPROTO_IP) |
| 130 | * @so_rev_match: optname to check revision support of match |
| 131 | * @so_rev_target: optname to check revision support of target |
| 132 | */ |
| 133 | struct xtables_afinfo { |
| 134 | const char *kmod; |
| 135 | const char *libprefix; |
| 136 | uint8_t family; |
| 137 | uint8_t ipproto; |
| 138 | int so_rev_match; |
| 139 | int so_rev_target; |
| 140 | }; |
| 141 | |
| 142 | static const struct xtables_afinfo afinfo_ipv4 = { |
| 143 | .kmod = "ip_tables", |
| 144 | .libprefix = "libipt_", |
| 145 | .family = NFPROTO_IPV4, |
| 146 | .ipproto = IPPROTO_IP, |
| 147 | .so_rev_match = IPT_SO_GET_REVISION_MATCH, |
| 148 | .so_rev_target = IPT_SO_GET_REVISION_TARGET, |
| 149 | }; |
| 150 | |
| 151 | static const struct xtables_afinfo afinfo_ipv6 = { |
| 152 | .kmod = "ip6_tables", |
| 153 | .libprefix = "libip6t_", |
| 154 | .family = NFPROTO_IPV6, |
| 155 | .ipproto = IPPROTO_IPV6, |
| 156 | .so_rev_match = IP6T_SO_GET_REVISION_MATCH, |
| 157 | .so_rev_target = IP6T_SO_GET_REVISION_TARGET, |
| 158 | }; |
| 159 | |
| 160 | static const struct xtables_afinfo *afinfo; |
| 161 | |
| 162 | /** |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 163 | * Program will set this to its own name. |
| 164 | */ |
| 165 | const char *xtables_program_name; |
| 166 | |
Jan Engelhardt | 39bf9c8 | 2009-01-27 15:59:06 +0100 | [diff] [blame] | 167 | /* Search path for Xtables .so files */ |
| 168 | static const char *xtables_libdir; |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 169 | |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 170 | /* the path to command to load kernel module */ |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 171 | const char *xtables_modprobe_program; |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 172 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 173 | /* Keeping track of external matches and targets: linked lists. */ |
| 174 | struct xtables_match *xtables_matches; |
| 175 | struct xtables_target *xtables_targets; |
| 176 | |
Jan Engelhardt | 39bf9c8 | 2009-01-27 15:59:06 +0100 | [diff] [blame] | 177 | void xtables_init(void) |
| 178 | { |
| 179 | xtables_libdir = getenv("XTABLES_LIBDIR"); |
| 180 | if (xtables_libdir != NULL) |
| 181 | return; |
| 182 | xtables_libdir = getenv("IPTABLES_LIB_DIR"); |
| 183 | if (xtables_libdir != NULL) { |
| 184 | fprintf(stderr, "IPTABLES_LIB_DIR is deprecated, " |
| 185 | "use XTABLES_LIBDIR.\n"); |
| 186 | return; |
| 187 | } |
Jan Engelhardt | ec93419 | 2009-02-10 09:54:04 +0100 | [diff] [blame] | 188 | /* |
| 189 | * Well yes, IP6TABLES_LIB_DIR is of lower priority over |
| 190 | * IPTABLES_LIB_DIR since this moved to libxtables; I think that is ok |
| 191 | * for these env vars are deprecated anyhow, and in light of the |
| 192 | * (shared) libxt_*.so files, makes less sense to have |
| 193 | * IPTABLES_LIB_DIR != IP6TABLES_LIB_DIR. |
| 194 | */ |
| 195 | xtables_libdir = getenv("IP6TABLES_LIB_DIR"); |
| 196 | if (xtables_libdir != NULL) { |
| 197 | fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated, " |
| 198 | "use XTABLES_LIBDIR.\n"); |
| 199 | return; |
| 200 | } |
Jan Engelhardt | 39bf9c8 | 2009-01-27 15:59:06 +0100 | [diff] [blame] | 201 | xtables_libdir = XTABLES_LIBDIR; |
| 202 | } |
| 203 | |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 204 | void xtables_set_nfproto(uint8_t nfproto) |
| 205 | { |
| 206 | switch (nfproto) { |
| 207 | case NFPROTO_IPV4: |
| 208 | afinfo = &afinfo_ipv4; |
| 209 | break; |
| 210 | case NFPROTO_IPV6: |
| 211 | afinfo = &afinfo_ipv6; |
| 212 | break; |
| 213 | default: |
| 214 | fprintf(stderr, "libxtables: unhandled NFPROTO in %s\n", |
| 215 | __func__); |
| 216 | } |
| 217 | } |
| 218 | |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 219 | /** |
Jamal Hadi Salim | 7e4db2f | 2009-02-13 09:14:17 -0500 | [diff] [blame^] | 220 | * xtables_set_params - set the global parameters used by xtables |
| 221 | * @xtp: input xtables_globals structure |
| 222 | * |
| 223 | * The app is expected to pass a valid xtables_globals data-filled |
| 224 | * with proper values |
| 225 | * @xtp cannot be NULL |
| 226 | * |
| 227 | * Returns -1 on failure to set and 0 on success |
| 228 | */ |
| 229 | int xtables_set_params(struct xtables_globals *xtp) |
| 230 | { |
| 231 | if (!xtp) { |
| 232 | fprintf(stderr, "%s: Illegal global params\n",__func__); |
| 233 | return -1; |
| 234 | } |
| 235 | |
| 236 | xt_params = xtp; |
| 237 | |
| 238 | if (!xt_params->exit_err) |
| 239 | xt_params->exit_err = basic_exit_err; |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | int xtables_init_all(struct xtables_globals *xtp, uint8_t nfproto) |
| 245 | { |
| 246 | xtables_init(); |
| 247 | xtables_set_nfproto(nfproto); |
| 248 | return xtables_set_params(xtp); |
| 249 | } |
| 250 | |
| 251 | /** |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 252 | * xtables_*alloc - wrappers that exit on failure |
| 253 | */ |
| 254 | void *xtables_calloc(size_t count, size_t size) |
Yasuyuki KOZAKAI | 3dfa448 | 2007-07-24 05:45:33 +0000 | [diff] [blame] | 255 | { |
| 256 | void *p; |
| 257 | |
| 258 | if ((p = calloc(count, size)) == NULL) { |
| 259 | perror("ip[6]tables: calloc failed"); |
| 260 | exit(1); |
| 261 | } |
| 262 | |
| 263 | return p; |
| 264 | } |
| 265 | |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 266 | void *xtables_malloc(size_t size) |
Yasuyuki KOZAKAI | 3dfa448 | 2007-07-24 05:45:33 +0000 | [diff] [blame] | 267 | { |
| 268 | void *p; |
| 269 | |
| 270 | if ((p = malloc(size)) == NULL) { |
| 271 | perror("ip[6]tables: malloc failed"); |
| 272 | exit(1); |
| 273 | } |
| 274 | |
| 275 | return p; |
| 276 | } |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 277 | |
| 278 | static char *get_modprobe(void) |
| 279 | { |
| 280 | int procfile; |
| 281 | char *ret; |
| 282 | |
| 283 | #define PROCFILE_BUFSIZ 1024 |
| 284 | procfile = open(PROC_SYS_MODPROBE, O_RDONLY); |
| 285 | if (procfile < 0) |
| 286 | return NULL; |
| 287 | |
| 288 | ret = (char *) malloc(PROCFILE_BUFSIZ); |
| 289 | if (ret) { |
| 290 | memset(ret, 0, PROCFILE_BUFSIZ); |
| 291 | switch (read(procfile, ret, PROCFILE_BUFSIZ)) { |
| 292 | case -1: goto fail; |
| 293 | case PROCFILE_BUFSIZ: goto fail; /* Partial read. Wierd */ |
| 294 | } |
| 295 | if (ret[strlen(ret)-1]=='\n') |
| 296 | ret[strlen(ret)-1]=0; |
| 297 | close(procfile); |
| 298 | return ret; |
| 299 | } |
| 300 | fail: |
| 301 | free(ret); |
| 302 | close(procfile); |
| 303 | return NULL; |
| 304 | } |
| 305 | |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 306 | int xtables_insmod(const char *modname, const char *modprobe, bool quiet) |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 307 | { |
| 308 | char *buf = NULL; |
| 309 | char *argv[4]; |
| 310 | int status; |
| 311 | |
| 312 | /* If they don't explicitly set it, read out of kernel */ |
| 313 | if (!modprobe) { |
| 314 | buf = get_modprobe(); |
| 315 | if (!buf) |
| 316 | return -1; |
| 317 | modprobe = buf; |
| 318 | } |
| 319 | |
Jan Engelhardt | c19f880 | 2009-02-12 01:28:35 +0100 | [diff] [blame] | 320 | /* |
| 321 | * Need to flush the buffer, or the child may output it again |
| 322 | * when switching the program thru execv. |
| 323 | */ |
| 324 | fflush(stdout); |
| 325 | |
Yasuyuki KOZAKAI | 0b82e8e | 2007-07-24 05:47:40 +0000 | [diff] [blame] | 326 | switch (fork()) { |
| 327 | case 0: |
| 328 | argv[0] = (char *)modprobe; |
| 329 | argv[1] = (char *)modname; |
| 330 | if (quiet) { |
| 331 | argv[2] = "-q"; |
| 332 | argv[3] = NULL; |
| 333 | } else { |
| 334 | argv[2] = NULL; |
| 335 | argv[3] = NULL; |
| 336 | } |
| 337 | execv(argv[0], argv); |
| 338 | |
| 339 | /* not usually reached */ |
| 340 | exit(1); |
| 341 | case -1: |
| 342 | return -1; |
| 343 | |
| 344 | default: /* parent */ |
| 345 | wait(&status); |
| 346 | } |
| 347 | |
| 348 | free(buf); |
| 349 | if (WIFEXITED(status) && WEXITSTATUS(status) == 0) |
| 350 | return 0; |
| 351 | return -1; |
| 352 | } |
| 353 | |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 354 | int xtables_load_ko(const char *modprobe, bool quiet) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 355 | { |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 356 | static bool loaded = false; |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 357 | static int ret = -1; |
| 358 | |
| 359 | if (!loaded) { |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 360 | ret = xtables_insmod(afinfo->kmod, modprobe, quiet); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 361 | loaded = (ret == 0); |
| 362 | } |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 367 | /** |
| 368 | * xtables_strtou{i,l} - string to number conversion |
| 369 | * @s: input string |
| 370 | * @end: like strtoul's "end" pointer |
| 371 | * @value: pointer for result |
| 372 | * @min: minimum accepted value |
| 373 | * @max: maximum accepted value |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 374 | * |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 375 | * If @end is NULL, we assume the caller wants a "strict strtoul", and hence |
| 376 | * "15a" is rejected. |
| 377 | * In either case, the value obtained is compared for min-max compliance. |
| 378 | * Base is always 0, i.e. autodetect depending on @s. |
| 379 | * |
| 380 | * Returns true/false whether number was accepted. On failure, *value has |
| 381 | * undefined contents. |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 382 | */ |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 383 | bool xtables_strtoul(const char *s, char **end, unsigned long *value, |
| 384 | unsigned long min, unsigned long max) |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 385 | { |
| 386 | unsigned long v; |
| 387 | char *my_end; |
| 388 | |
| 389 | errno = 0; |
| 390 | v = strtoul(s, &my_end, 0); |
| 391 | |
| 392 | if (my_end == s) |
| 393 | return false; |
| 394 | if (end != NULL) |
| 395 | *end = my_end; |
| 396 | |
| 397 | if (errno != ERANGE && min <= v && (max == 0 || v <= max)) { |
| 398 | if (value != NULL) |
| 399 | *value = v; |
| 400 | if (end == NULL) |
| 401 | return *my_end == '\0'; |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | return false; |
| 406 | } |
| 407 | |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 408 | bool xtables_strtoui(const char *s, char **end, unsigned int *value, |
| 409 | unsigned int min, unsigned int max) |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 410 | { |
| 411 | unsigned long v; |
| 412 | bool ret; |
| 413 | |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 414 | ret = xtables_strtoul(s, end, &v, min, max); |
Jan Engelhardt | cd9e7aa | 2008-01-20 13:18:54 +0000 | [diff] [blame] | 415 | if (value != NULL) |
| 416 | *value = v; |
| 417 | return ret; |
| 418 | } |
| 419 | |
Jan Engelhardt | aae6be9 | 2009-01-30 04:24:47 +0100 | [diff] [blame] | 420 | int xtables_service_to_port(const char *name, const char *proto) |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 421 | { |
| 422 | struct servent *service; |
| 423 | |
| 424 | if ((service = getservbyname(name, proto)) != NULL) |
| 425 | return ntohs((unsigned short) service->s_port); |
| 426 | |
| 427 | return -1; |
| 428 | } |
| 429 | |
Jan Engelhardt | aae6be9 | 2009-01-30 04:24:47 +0100 | [diff] [blame] | 430 | u_int16_t xtables_parse_port(const char *port, const char *proto) |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 431 | { |
Jan Engelhardt | 7a236f4 | 2008-03-03 12:30:41 +0100 | [diff] [blame] | 432 | unsigned int portnum; |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 433 | |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 434 | if (xtables_strtoui(port, NULL, &portnum, 0, UINT16_MAX) || |
Jan Engelhardt | aae6be9 | 2009-01-30 04:24:47 +0100 | [diff] [blame] | 435 | (portnum = xtables_service_to_port(port, proto)) != (unsigned)-1) |
Jan Engelhardt | 213e185 | 2009-01-27 17:24:34 +0100 | [diff] [blame] | 436 | return portnum; |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 437 | |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 438 | xt_params->exit_err(PARAMETER_PROBLEM, |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 439 | "invalid port/service `%s' specified", port); |
| 440 | } |
| 441 | |
Jan Engelhardt | aae6be9 | 2009-01-30 04:24:47 +0100 | [diff] [blame] | 442 | void xtables_parse_interface(const char *arg, char *vianame, |
| 443 | unsigned char *mask) |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 444 | { |
| 445 | int vialen = strlen(arg); |
| 446 | unsigned int i; |
| 447 | |
| 448 | memset(mask, 0, IFNAMSIZ); |
| 449 | memset(vianame, 0, IFNAMSIZ); |
| 450 | |
| 451 | if (vialen + 1 > IFNAMSIZ) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 452 | xt_params->exit_err(PARAMETER_PROBLEM, |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 453 | "interface name `%s' must be shorter than IFNAMSIZ" |
| 454 | " (%i)", arg, IFNAMSIZ-1); |
| 455 | |
| 456 | strcpy(vianame, arg); |
| 457 | if ((vialen == 0) || (vialen == 1 && vianame[0] == '+')) |
| 458 | memset(mask, 0, IFNAMSIZ); |
| 459 | else if (vianame[vialen - 1] == '+') { |
| 460 | memset(mask, 0xFF, vialen - 1); |
| 461 | memset(mask + vialen - 1, 0, IFNAMSIZ - vialen + 1); |
| 462 | /* Don't remove `+' here! -HW */ |
| 463 | } else { |
| 464 | /* Include nul-terminator in match */ |
| 465 | memset(mask, 0xFF, vialen + 1); |
| 466 | memset(mask + vialen + 1, 0, IFNAMSIZ - vialen - 1); |
| 467 | for (i = 0; vianame[i]; i++) { |
| 468 | if (vianame[i] == ':' || |
| 469 | vianame[i] == '!' || |
| 470 | vianame[i] == '*') { |
Max Kellermann | aae4f82 | 2007-10-17 16:36:49 +0000 | [diff] [blame] | 471 | fprintf(stderr, |
| 472 | "Warning: weird character in interface" |
| 473 | " `%s' (No aliases, :, ! or *).\n", |
| 474 | vianame); |
Yasuyuki KOZAKAI | 04f8c54 | 2007-07-24 05:53:48 +0000 | [diff] [blame] | 475 | break; |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
Jan Engelhardt | cb25af8 | 2008-04-14 18:37:57 +0200 | [diff] [blame] | 481 | #ifndef NO_SHARED_LIBS |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 482 | static void *load_extension(const char *search_path, const char *prefix, |
| 483 | const char *name, bool is_target) |
| 484 | { |
| 485 | const char *dir = search_path, *next; |
| 486 | void *ptr = NULL; |
| 487 | struct stat sb; |
| 488 | char path[256]; |
| 489 | |
| 490 | do { |
| 491 | next = strchr(dir, ':'); |
| 492 | if (next == NULL) |
| 493 | next = dir + strlen(dir); |
| 494 | snprintf(path, sizeof(path), "%.*s/libxt_%s.so", |
Jan Engelhardt | 2c0a0c9 | 2008-04-14 15:58:17 +0200 | [diff] [blame] | 495 | (unsigned int)(next - dir), dir, name); |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 496 | |
| 497 | if (dlopen(path, RTLD_NOW) != NULL) { |
| 498 | /* Found library. If it didn't register itself, |
| 499 | maybe they specified target as match. */ |
| 500 | if (is_target) |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 501 | ptr = xtables_find_target(name, XTF_DONT_LOAD); |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 502 | else |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 503 | ptr = xtables_find_match(name, |
| 504 | XTF_DONT_LOAD, NULL); |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 505 | } else if (stat(path, &sb) == 0) { |
| 506 | fprintf(stderr, "%s: %s\n", path, dlerror()); |
| 507 | } |
| 508 | |
| 509 | if (ptr != NULL) |
| 510 | return ptr; |
| 511 | |
| 512 | snprintf(path, sizeof(path), "%.*s/%s%s.so", |
Jan Engelhardt | 2c0a0c9 | 2008-04-14 15:58:17 +0200 | [diff] [blame] | 513 | (unsigned int)(next - dir), dir, prefix, name); |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 514 | if (dlopen(path, RTLD_NOW) != NULL) { |
| 515 | if (is_target) |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 516 | ptr = xtables_find_target(name, XTF_DONT_LOAD); |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 517 | else |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 518 | ptr = xtables_find_match(name, |
| 519 | XTF_DONT_LOAD, NULL); |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 520 | } else if (stat(path, &sb) == 0) { |
| 521 | fprintf(stderr, "%s: %s\n", path, dlerror()); |
| 522 | } |
| 523 | |
| 524 | if (ptr != NULL) |
| 525 | return ptr; |
| 526 | |
| 527 | dir = next + 1; |
| 528 | } while (*next != '\0'); |
| 529 | |
| 530 | return NULL; |
| 531 | } |
Jan Engelhardt | cb25af8 | 2008-04-14 18:37:57 +0200 | [diff] [blame] | 532 | #endif |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 533 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 534 | struct xtables_match * |
| 535 | xtables_find_match(const char *name, enum xtables_tryload tryload, |
| 536 | struct xtables_rule_match **matches) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 537 | { |
| 538 | struct xtables_match *ptr; |
| 539 | const char *icmp6 = "icmp6"; |
| 540 | |
| 541 | /* This is ugly as hell. Nonetheless, there is no way of changing |
| 542 | * this without hurting backwards compatibility */ |
| 543 | if ( (strcmp(name,"icmpv6") == 0) || |
| 544 | (strcmp(name,"ipv6-icmp") == 0) || |
| 545 | (strcmp(name,"icmp6") == 0) ) |
| 546 | name = icmp6; |
| 547 | |
| 548 | for (ptr = xtables_matches; ptr; ptr = ptr->next) { |
| 549 | if (strcmp(name, ptr->name) == 0) { |
| 550 | struct xtables_match *clone; |
| 551 | |
| 552 | /* First match of this type: */ |
| 553 | if (ptr->m == NULL) |
| 554 | break; |
| 555 | |
| 556 | /* Second and subsequent clones */ |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 557 | clone = xtables_malloc(sizeof(struct xtables_match)); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 558 | memcpy(clone, ptr, sizeof(struct xtables_match)); |
| 559 | clone->mflags = 0; |
| 560 | /* This is a clone: */ |
| 561 | clone->next = clone; |
| 562 | |
| 563 | ptr = clone; |
| 564 | break; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | #ifndef NO_SHARED_LIBS |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 569 | if (!ptr && tryload != XTF_DONT_LOAD && tryload != XTF_DURING_LOAD) { |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 570 | ptr = load_extension(xtables_libdir, afinfo->libprefix, |
Jan Engelhardt | 39bf9c8 | 2009-01-27 15:59:06 +0100 | [diff] [blame] | 571 | name, false); |
Yasuyuki KOZAKAI | 170af8c | 2007-08-04 05:22:17 +0000 | [diff] [blame] | 572 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 573 | if (ptr == NULL && tryload == XTF_LOAD_MUST_SUCCEED) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 574 | xt_params->exit_err(PARAMETER_PROBLEM, |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 575 | "Couldn't load match `%s':%s\n", |
| 576 | name, dlerror()); |
| 577 | } |
| 578 | #else |
| 579 | if (ptr && !ptr->loaded) { |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 580 | if (tryload != XTF_DONT_LOAD) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 581 | ptr->loaded = 1; |
| 582 | else |
| 583 | ptr = NULL; |
| 584 | } |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 585 | if(!ptr && (tryload == XTF_LOAD_MUST_SUCCEED)) { |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 586 | xt_params->exit_err(PARAMETER_PROBLEM, |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 587 | "Couldn't find match `%s'\n", name); |
| 588 | } |
| 589 | #endif |
| 590 | |
| 591 | if (ptr && matches) { |
| 592 | struct xtables_rule_match **i; |
| 593 | struct xtables_rule_match *newentry; |
| 594 | |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 595 | newentry = xtables_malloc(sizeof(struct xtables_rule_match)); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 596 | |
| 597 | for (i = matches; *i; i = &(*i)->next) { |
| 598 | if (strcmp(name, (*i)->match->name) == 0) |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 599 | (*i)->completed = true; |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 600 | } |
| 601 | newentry->match = ptr; |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 602 | newentry->completed = false; |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 603 | newentry->next = NULL; |
| 604 | *i = newentry; |
| 605 | } |
| 606 | |
| 607 | return ptr; |
| 608 | } |
| 609 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 610 | struct xtables_target * |
| 611 | xtables_find_target(const char *name, enum xtables_tryload tryload) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 612 | { |
| 613 | struct xtables_target *ptr; |
| 614 | |
| 615 | /* Standard target? */ |
| 616 | if (strcmp(name, "") == 0 |
| 617 | || strcmp(name, XTC_LABEL_ACCEPT) == 0 |
| 618 | || strcmp(name, XTC_LABEL_DROP) == 0 |
| 619 | || strcmp(name, XTC_LABEL_QUEUE) == 0 |
| 620 | || strcmp(name, XTC_LABEL_RETURN) == 0) |
| 621 | name = "standard"; |
| 622 | |
| 623 | for (ptr = xtables_targets; ptr; ptr = ptr->next) { |
| 624 | if (strcmp(name, ptr->name) == 0) |
| 625 | break; |
| 626 | } |
| 627 | |
| 628 | #ifndef NO_SHARED_LIBS |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 629 | if (!ptr && tryload != XTF_DONT_LOAD && tryload != XTF_DURING_LOAD) { |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 630 | ptr = load_extension(xtables_libdir, afinfo->libprefix, |
Jan Engelhardt | 39bf9c8 | 2009-01-27 15:59:06 +0100 | [diff] [blame] | 631 | name, true); |
Yasuyuki KOZAKAI | 170af8c | 2007-08-04 05:22:17 +0000 | [diff] [blame] | 632 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 633 | if (ptr == NULL && tryload == XTF_LOAD_MUST_SUCCEED) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 634 | xt_params->exit_err(PARAMETER_PROBLEM, |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 635 | "Couldn't load target `%s':%s\n", |
| 636 | name, dlerror()); |
| 637 | } |
| 638 | #else |
| 639 | if (ptr && !ptr->loaded) { |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 640 | if (tryload != XTF_DONT_LOAD) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 641 | ptr->loaded = 1; |
| 642 | else |
| 643 | ptr = NULL; |
| 644 | } |
| 645 | if(!ptr && (tryload == LOAD_MUST_SUCCEED)) { |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 646 | xt_params->exit_err(PARAMETER_PROBLEM, |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 647 | "Couldn't find target `%s'\n", name); |
| 648 | } |
| 649 | #endif |
| 650 | |
| 651 | if (ptr) |
| 652 | ptr->used = 1; |
| 653 | |
| 654 | return ptr; |
| 655 | } |
| 656 | |
| 657 | static int compatible_revision(const char *name, u_int8_t revision, int opt) |
| 658 | { |
| 659 | struct xt_get_revision rev; |
| 660 | socklen_t s = sizeof(rev); |
| 661 | int max_rev, sockfd; |
| 662 | |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 663 | sockfd = socket(afinfo->family, SOCK_RAW, IPPROTO_RAW); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 664 | if (sockfd < 0) { |
Patrick McHardy | df1ef38 | 2007-12-03 15:32:28 +0000 | [diff] [blame] | 665 | if (errno == EPERM) { |
| 666 | /* revision 0 is always supported. */ |
| 667 | if (revision != 0) |
| 668 | fprintf(stderr, "Could not determine whether " |
| 669 | "revision %u is supported, " |
| 670 | "assuming it is.\n", |
| 671 | revision); |
| 672 | return 1; |
| 673 | } |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 674 | fprintf(stderr, "Could not open socket to kernel: %s\n", |
| 675 | strerror(errno)); |
| 676 | exit(1); |
| 677 | } |
| 678 | |
Jan Engelhardt | c021c3c | 2009-01-27 15:10:05 +0100 | [diff] [blame] | 679 | xtables_load_ko(xtables_modprobe_program, true); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 680 | |
| 681 | strcpy(rev.name, name); |
| 682 | rev.revision = revision; |
| 683 | |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 684 | max_rev = getsockopt(sockfd, afinfo->ipproto, opt, &rev, &s); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 685 | if (max_rev < 0) { |
| 686 | /* Definitely don't support this? */ |
| 687 | if (errno == ENOENT || errno == EPROTONOSUPPORT) { |
| 688 | close(sockfd); |
| 689 | return 0; |
| 690 | } else if (errno == ENOPROTOOPT) { |
| 691 | close(sockfd); |
| 692 | /* Assume only revision 0 support (old kernel) */ |
| 693 | return (revision == 0); |
| 694 | } else { |
| 695 | fprintf(stderr, "getsockopt failed strangely: %s\n", |
| 696 | strerror(errno)); |
| 697 | exit(1); |
| 698 | } |
| 699 | } |
| 700 | close(sockfd); |
| 701 | return 1; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | static int compatible_match_revision(const char *name, u_int8_t revision) |
| 706 | { |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 707 | return compatible_revision(name, revision, afinfo->so_rev_match); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | static int compatible_target_revision(const char *name, u_int8_t revision) |
| 711 | { |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 712 | return compatible_revision(name, revision, afinfo->so_rev_target); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | void xtables_register_match(struct xtables_match *me) |
| 716 | { |
| 717 | struct xtables_match **i, *old; |
| 718 | |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 719 | if (strcmp(me->version, XTABLES_VERSION) != 0) { |
| 720 | fprintf(stderr, "%s: match \"%s\" has version \"%s\", " |
| 721 | "but \"%s\" is required.\n", |
| 722 | xtables_program_name, me->name, |
| 723 | me->version, XTABLES_VERSION); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 724 | exit(1); |
| 725 | } |
| 726 | |
| 727 | /* Revision field stole a char from name. */ |
| 728 | if (strlen(me->name) >= XT_FUNCTION_MAXNAMELEN-1) { |
| 729 | fprintf(stderr, "%s: target `%s' has invalid name\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 730 | xtables_program_name, me->name); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 731 | exit(1); |
| 732 | } |
| 733 | |
| 734 | if (me->family >= NPROTO) { |
| 735 | fprintf(stderr, |
| 736 | "%s: BUG: match %s has invalid protocol family\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 737 | xtables_program_name, me->name); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 738 | exit(1); |
| 739 | } |
| 740 | |
| 741 | /* ignore not interested match */ |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 742 | if (me->family != afinfo->family && me->family != AF_UNSPEC) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 743 | return; |
| 744 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 745 | old = xtables_find_match(me->name, XTF_DURING_LOAD, NULL); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 746 | if (old) { |
Jan Engelhardt | 23545c2 | 2008-02-14 04:23:04 +0100 | [diff] [blame] | 747 | if (old->revision == me->revision && |
| 748 | old->family == me->family) { |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 749 | fprintf(stderr, |
| 750 | "%s: match `%s' already registered.\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 751 | xtables_program_name, me->name); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 752 | exit(1); |
| 753 | } |
| 754 | |
| 755 | /* Now we have two (or more) options, check compatibility. */ |
| 756 | if (compatible_match_revision(old->name, old->revision) |
| 757 | && old->revision > me->revision) |
| 758 | return; |
| 759 | |
Jan Engelhardt | 23545c2 | 2008-02-14 04:23:04 +0100 | [diff] [blame] | 760 | /* See if new match can be used. */ |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 761 | if (!compatible_match_revision(me->name, me->revision)) |
| 762 | return; |
| 763 | |
Jan Engelhardt | 23545c2 | 2008-02-14 04:23:04 +0100 | [diff] [blame] | 764 | /* Prefer !AF_UNSPEC over AF_UNSPEC for same revision. */ |
| 765 | if (old->revision == me->revision && me->family == AF_UNSPEC) |
| 766 | return; |
| 767 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 768 | /* Delete old one. */ |
| 769 | for (i = &xtables_matches; *i!=old; i = &(*i)->next); |
| 770 | *i = old->next; |
| 771 | } |
| 772 | |
| 773 | if (me->size != XT_ALIGN(me->size)) { |
| 774 | fprintf(stderr, "%s: match `%s' has invalid size %u.\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 775 | xtables_program_name, me->name, (unsigned int)me->size); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 776 | exit(1); |
| 777 | } |
| 778 | |
| 779 | /* Append to list. */ |
| 780 | for (i = &xtables_matches; *i; i = &(*i)->next); |
| 781 | me->next = NULL; |
| 782 | *i = me; |
| 783 | |
| 784 | me->m = NULL; |
| 785 | me->mflags = 0; |
| 786 | } |
| 787 | |
| 788 | void xtables_register_target(struct xtables_target *me) |
| 789 | { |
| 790 | struct xtables_target *old; |
| 791 | |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 792 | if (strcmp(me->version, XTABLES_VERSION) != 0) { |
| 793 | fprintf(stderr, "%s: target \"%s\" has version \"%s\", " |
| 794 | "but \"%s\" is required.\n", |
| 795 | xtables_program_name, me->name, |
| 796 | me->version, XTABLES_VERSION); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 797 | exit(1); |
| 798 | } |
| 799 | |
| 800 | /* Revision field stole a char from name. */ |
| 801 | if (strlen(me->name) >= XT_FUNCTION_MAXNAMELEN-1) { |
| 802 | fprintf(stderr, "%s: target `%s' has invalid name\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 803 | xtables_program_name, me->name); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 804 | exit(1); |
| 805 | } |
| 806 | |
| 807 | if (me->family >= NPROTO) { |
| 808 | fprintf(stderr, |
| 809 | "%s: BUG: target %s has invalid protocol family\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 810 | xtables_program_name, me->name); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 811 | exit(1); |
| 812 | } |
| 813 | |
| 814 | /* ignore not interested target */ |
Jan Engelhardt | 77f48c2 | 2009-02-07 19:59:53 +0100 | [diff] [blame] | 815 | if (me->family != afinfo->family && me->family != AF_UNSPEC) |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 816 | return; |
| 817 | |
Jan Engelhardt | 2338efd | 2009-01-27 15:23:01 +0100 | [diff] [blame] | 818 | old = xtables_find_target(me->name, XTF_DURING_LOAD); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 819 | if (old) { |
| 820 | struct xtables_target **i; |
| 821 | |
Jan Engelhardt | 23545c2 | 2008-02-14 04:23:04 +0100 | [diff] [blame] | 822 | if (old->revision == me->revision && |
| 823 | old->family == me->family) { |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 824 | fprintf(stderr, |
| 825 | "%s: target `%s' already registered.\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 826 | xtables_program_name, me->name); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 827 | exit(1); |
| 828 | } |
| 829 | |
| 830 | /* Now we have two (or more) options, check compatibility. */ |
| 831 | if (compatible_target_revision(old->name, old->revision) |
| 832 | && old->revision > me->revision) |
| 833 | return; |
| 834 | |
Jan Engelhardt | 23545c2 | 2008-02-14 04:23:04 +0100 | [diff] [blame] | 835 | /* See if new target can be used. */ |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 836 | if (!compatible_target_revision(me->name, me->revision)) |
| 837 | return; |
| 838 | |
Jan Engelhardt | 23545c2 | 2008-02-14 04:23:04 +0100 | [diff] [blame] | 839 | /* Prefer !AF_UNSPEC over AF_UNSPEC for same revision. */ |
| 840 | if (old->revision == me->revision && me->family == AF_UNSPEC) |
| 841 | return; |
| 842 | |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 843 | /* Delete old one. */ |
| 844 | for (i = &xtables_targets; *i!=old; i = &(*i)->next); |
| 845 | *i = old->next; |
| 846 | } |
| 847 | |
| 848 | if (me->size != XT_ALIGN(me->size)) { |
| 849 | fprintf(stderr, "%s: target `%s' has invalid size %u.\n", |
Jan Engelhardt | dacafa5 | 2009-01-27 20:56:23 +0100 | [diff] [blame] | 850 | xtables_program_name, me->name, (unsigned int)me->size); |
Yasuyuki KOZAKAI | 0d502bc | 2007-07-24 05:52:07 +0000 | [diff] [blame] | 851 | exit(1); |
| 852 | } |
| 853 | |
| 854 | /* Prepend to list. */ |
| 855 | me->next = xtables_targets; |
| 856 | xtables_targets = me; |
| 857 | me->t = NULL; |
| 858 | me->tflags = 0; |
| 859 | } |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 860 | |
Jan Engelhardt | a41545c | 2009-01-27 21:27:19 +0100 | [diff] [blame] | 861 | /** |
| 862 | * xtables_param_act - act on condition |
| 863 | * @status: a constant from enum xtables_exittype |
| 864 | * |
| 865 | * %XTF_ONLY_ONCE: print error message that option may only be used once. |
| 866 | * @p1: module name (e.g. "mark") |
| 867 | * @p2(...): option in conflict (e.g. "--mark") |
| 868 | * @p3(...): condition to match on (see extensions/ for examples) |
| 869 | * |
| 870 | * %XTF_NO_INVERT: option does not support inversion |
| 871 | * @p1: module name |
| 872 | * @p2: option in conflict |
| 873 | * @p3: condition to match on |
| 874 | * |
| 875 | * %XTF_BAD_VALUE: bad value for option |
| 876 | * @p1: module name |
| 877 | * @p2: option with which the problem occured (e.g. "--mark") |
| 878 | * @p3: string the user passed in (e.g. "99999999999999") |
| 879 | * |
| 880 | * %XTF_ONE_ACTION: two mutually exclusive actions have been specified |
| 881 | * @p1: module name |
| 882 | * |
| 883 | * Displays an error message and exits the program. |
| 884 | */ |
| 885 | void xtables_param_act(unsigned int status, const char *p1, ...) |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 886 | { |
| 887 | const char *p2, *p3; |
| 888 | va_list args; |
| 889 | bool b; |
| 890 | |
| 891 | va_start(args, p1); |
| 892 | |
| 893 | switch (status) { |
Jan Engelhardt | a41545c | 2009-01-27 21:27:19 +0100 | [diff] [blame] | 894 | case XTF_ONLY_ONCE: |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 895 | p2 = va_arg(args, const char *); |
| 896 | b = va_arg(args, unsigned int); |
| 897 | if (!b) |
| 898 | return; |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 899 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 900 | "%s: \"%s\" option may only be specified once", |
| 901 | p1, p2); |
| 902 | break; |
Jan Engelhardt | a41545c | 2009-01-27 21:27:19 +0100 | [diff] [blame] | 903 | case XTF_NO_INVERT: |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 904 | p2 = va_arg(args, const char *); |
| 905 | b = va_arg(args, unsigned int); |
| 906 | if (!b) |
| 907 | return; |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 908 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 909 | "%s: \"%s\" option cannot be inverted", p1, p2); |
| 910 | break; |
Jan Engelhardt | a41545c | 2009-01-27 21:27:19 +0100 | [diff] [blame] | 911 | case XTF_BAD_VALUE: |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 912 | p2 = va_arg(args, const char *); |
| 913 | p3 = va_arg(args, const char *); |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 914 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 915 | "%s: Bad value for \"%s\" option: \"%s\"", |
| 916 | p1, p2, p3); |
| 917 | break; |
Jan Engelhardt | a41545c | 2009-01-27 21:27:19 +0100 | [diff] [blame] | 918 | case XTF_ONE_ACTION: |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 919 | b = va_arg(args, unsigned int); |
| 920 | if (!b) |
| 921 | return; |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 922 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 923 | "%s: At most one action is possible", p1); |
| 924 | break; |
| 925 | default: |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 926 | xt_params->exit_err(status, p1, args); |
Jan Engelhardt | aafd269 | 2008-01-20 13:19:40 +0000 | [diff] [blame] | 927 | break; |
| 928 | } |
| 929 | |
| 930 | va_end(args); |
| 931 | } |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 932 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 933 | const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 934 | { |
| 935 | static char buf[20]; |
| 936 | const unsigned char *bytep = (const void *)&addrp->s_addr; |
| 937 | |
| 938 | sprintf(buf, "%u.%u.%u.%u", bytep[0], bytep[1], bytep[2], bytep[3]); |
| 939 | return buf; |
| 940 | } |
| 941 | |
| 942 | static const char *ipaddr_to_host(const struct in_addr *addr) |
| 943 | { |
| 944 | struct hostent *host; |
| 945 | |
| 946 | host = gethostbyaddr(addr, sizeof(struct in_addr), AF_INET); |
| 947 | if (host == NULL) |
| 948 | return NULL; |
| 949 | |
| 950 | return host->h_name; |
| 951 | } |
| 952 | |
| 953 | static const char *ipaddr_to_network(const struct in_addr *addr) |
| 954 | { |
| 955 | struct netent *net; |
| 956 | |
| 957 | if ((net = getnetbyaddr(ntohl(addr->s_addr), AF_INET)) != NULL) |
| 958 | return net->n_name; |
| 959 | |
| 960 | return NULL; |
| 961 | } |
| 962 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 963 | const char *xtables_ipaddr_to_anyname(const struct in_addr *addr) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 964 | { |
| 965 | const char *name; |
| 966 | |
| 967 | if ((name = ipaddr_to_host(addr)) != NULL || |
| 968 | (name = ipaddr_to_network(addr)) != NULL) |
| 969 | return name; |
| 970 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 971 | return xtables_ipaddr_to_numeric(addr); |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 974 | const char *xtables_ipmask_to_numeric(const struct in_addr *mask) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 975 | { |
| 976 | static char buf[20]; |
| 977 | uint32_t maskaddr, bits; |
| 978 | int i; |
| 979 | |
| 980 | maskaddr = ntohl(mask->s_addr); |
| 981 | |
| 982 | if (maskaddr == 0xFFFFFFFFL) |
| 983 | /* we don't want to see "/32" */ |
| 984 | return ""; |
| 985 | |
| 986 | i = 32; |
| 987 | bits = 0xFFFFFFFEL; |
| 988 | while (--i >= 0 && maskaddr != bits) |
| 989 | bits <<= 1; |
| 990 | if (i >= 0) |
| 991 | sprintf(buf, "/%d", i); |
| 992 | else |
| 993 | /* mask was not a decent combination of 1's and 0's */ |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 994 | sprintf(buf, "/%s", xtables_ipaddr_to_numeric(mask)); |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 995 | |
| 996 | return buf; |
| 997 | } |
| 998 | |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 999 | static struct in_addr *__numeric_to_ipaddr(const char *dotted, bool is_mask) |
| 1000 | { |
| 1001 | static struct in_addr addr; |
| 1002 | unsigned char *addrp; |
| 1003 | unsigned int onebyte; |
| 1004 | char buf[20], *p, *q; |
| 1005 | int i; |
| 1006 | |
| 1007 | /* copy dotted string, because we need to modify it */ |
| 1008 | strncpy(buf, dotted, sizeof(buf) - 1); |
| 1009 | buf[sizeof(buf) - 1] = '\0'; |
| 1010 | addrp = (void *)&addr.s_addr; |
| 1011 | |
| 1012 | p = buf; |
| 1013 | for (i = 0; i < 3; ++i) { |
| 1014 | if ((q = strchr(p, '.')) == NULL) { |
| 1015 | if (is_mask) |
| 1016 | return NULL; |
| 1017 | |
| 1018 | /* autocomplete, this is a network address */ |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 1019 | if (!xtables_strtoui(p, NULL, &onebyte, 0, UINT8_MAX)) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1020 | return NULL; |
| 1021 | |
| 1022 | addrp[i] = onebyte; |
| 1023 | while (i < 3) |
| 1024 | addrp[++i] = 0; |
| 1025 | |
| 1026 | return &addr; |
| 1027 | } |
| 1028 | |
| 1029 | *q = '\0'; |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 1030 | if (!xtables_strtoui(p, NULL, &onebyte, 0, UINT8_MAX)) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1031 | return NULL; |
| 1032 | |
| 1033 | addrp[i] = onebyte; |
| 1034 | p = q + 1; |
| 1035 | } |
| 1036 | |
| 1037 | /* we have checked 3 bytes, now we check the last one */ |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 1038 | if (!xtables_strtoui(p, NULL, &onebyte, 0, UINT8_MAX)) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1039 | return NULL; |
| 1040 | |
| 1041 | addrp[3] = onebyte; |
| 1042 | return &addr; |
| 1043 | } |
| 1044 | |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 1045 | struct in_addr *xtables_numeric_to_ipaddr(const char *dotted) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1046 | { |
| 1047 | return __numeric_to_ipaddr(dotted, false); |
| 1048 | } |
| 1049 | |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 1050 | struct in_addr *xtables_numeric_to_ipmask(const char *dotted) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1051 | { |
| 1052 | return __numeric_to_ipaddr(dotted, true); |
| 1053 | } |
| 1054 | |
| 1055 | static struct in_addr *network_to_ipaddr(const char *name) |
| 1056 | { |
| 1057 | static struct in_addr addr; |
| 1058 | struct netent *net; |
| 1059 | |
| 1060 | if ((net = getnetbyname(name)) != NULL) { |
| 1061 | if (net->n_addrtype != AF_INET) |
| 1062 | return NULL; |
| 1063 | addr.s_addr = htonl(net->n_net); |
| 1064 | return &addr; |
| 1065 | } |
| 1066 | |
| 1067 | return NULL; |
| 1068 | } |
| 1069 | |
| 1070 | static struct in_addr *host_to_ipaddr(const char *name, unsigned int *naddr) |
| 1071 | { |
| 1072 | struct hostent *host; |
| 1073 | struct in_addr *addr; |
| 1074 | unsigned int i; |
| 1075 | |
| 1076 | *naddr = 0; |
| 1077 | if ((host = gethostbyname(name)) != NULL) { |
| 1078 | if (host->h_addrtype != AF_INET || |
| 1079 | host->h_length != sizeof(struct in_addr)) |
| 1080 | return NULL; |
| 1081 | |
| 1082 | while (host->h_addr_list[*naddr] != NULL) |
| 1083 | ++*naddr; |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 1084 | addr = xtables_calloc(*naddr, sizeof(struct in_addr) * *naddr); |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1085 | for (i = 0; i < *naddr; i++) |
| 1086 | memcpy(&addr[i], host->h_addr_list[i], |
| 1087 | sizeof(struct in_addr)); |
| 1088 | return addr; |
| 1089 | } |
| 1090 | |
| 1091 | return NULL; |
| 1092 | } |
| 1093 | |
| 1094 | static struct in_addr * |
| 1095 | ipparse_hostnetwork(const char *name, unsigned int *naddrs) |
| 1096 | { |
| 1097 | struct in_addr *addrptmp, *addrp; |
| 1098 | |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 1099 | if ((addrptmp = xtables_numeric_to_ipaddr(name)) != NULL || |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1100 | (addrptmp = network_to_ipaddr(name)) != NULL) { |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 1101 | addrp = xtables_malloc(sizeof(struct in_addr)); |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1102 | memcpy(addrp, addrptmp, sizeof(*addrp)); |
| 1103 | *naddrs = 1; |
| 1104 | return addrp; |
| 1105 | } |
| 1106 | if ((addrptmp = host_to_ipaddr(name, naddrs)) != NULL) |
| 1107 | return addrptmp; |
| 1108 | |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 1109 | xt_params->exit_err(PARAMETER_PROBLEM, "host/network `%s' not found", name); |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | static struct in_addr *parse_ipmask(const char *mask) |
| 1113 | { |
| 1114 | static struct in_addr maskaddr; |
| 1115 | struct in_addr *addrp; |
| 1116 | unsigned int bits; |
| 1117 | |
| 1118 | if (mask == NULL) { |
| 1119 | /* no mask at all defaults to 32 bits */ |
| 1120 | maskaddr.s_addr = 0xFFFFFFFF; |
| 1121 | return &maskaddr; |
| 1122 | } |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 1123 | if ((addrp = xtables_numeric_to_ipmask(mask)) != NULL) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1124 | /* dotted_to_addr already returns a network byte order addr */ |
| 1125 | return addrp; |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 1126 | if (!xtables_strtoui(mask, NULL, &bits, 0, 32)) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 1127 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1128 | "invalid mask `%s' specified", mask); |
| 1129 | if (bits != 0) { |
| 1130 | maskaddr.s_addr = htonl(0xFFFFFFFF << (32 - bits)); |
| 1131 | return &maskaddr; |
| 1132 | } |
| 1133 | |
| 1134 | maskaddr.s_addr = 0U; |
| 1135 | return &maskaddr; |
| 1136 | } |
| 1137 | |
Jan Engelhardt | a0baae8 | 2009-01-30 04:32:50 +0100 | [diff] [blame] | 1138 | /** |
| 1139 | * xtables_ipparse_any - transform arbitrary name to in_addr |
| 1140 | * |
| 1141 | * Possible inputs (pseudo regex): |
| 1142 | * m{^($hostname|$networkname|$ipaddr)(/$mask)?} |
| 1143 | * "1.2.3.4/5", "1.2.3.4", "hostname", "networkname" |
| 1144 | */ |
| 1145 | void xtables_ipparse_any(const char *name, struct in_addr **addrpp, |
| 1146 | struct in_addr *maskp, unsigned int *naddrs) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1147 | { |
| 1148 | unsigned int i, j, k, n; |
| 1149 | struct in_addr *addrp; |
| 1150 | char buf[256], *p; |
| 1151 | |
| 1152 | strncpy(buf, name, sizeof(buf) - 1); |
| 1153 | buf[sizeof(buf) - 1] = '\0'; |
| 1154 | if ((p = strrchr(buf, '/')) != NULL) { |
| 1155 | *p = '\0'; |
| 1156 | addrp = parse_ipmask(p + 1); |
| 1157 | } else { |
| 1158 | addrp = parse_ipmask(NULL); |
| 1159 | } |
| 1160 | memcpy(maskp, addrp, sizeof(*maskp)); |
| 1161 | |
| 1162 | /* if a null mask is given, the name is ignored, like in "any/0" */ |
| 1163 | if (maskp->s_addr == 0U) |
| 1164 | strcpy(buf, "0.0.0.0"); |
| 1165 | |
| 1166 | addrp = *addrpp = ipparse_hostnetwork(buf, naddrs); |
| 1167 | n = *naddrs; |
| 1168 | for (i = 0, j = 0; i < n; ++i) { |
| 1169 | addrp[j++].s_addr &= maskp->s_addr; |
| 1170 | for (k = 0; k < j - 1; ++k) |
| 1171 | if (addrp[k].s_addr == addrp[j-1].s_addr) { |
| 1172 | --*naddrs; |
| 1173 | --j; |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 1179 | const char *xtables_ip6addr_to_numeric(const struct in6_addr *addrp) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 1180 | { |
| 1181 | /* 0000:0000:0000:0000:0000:000.000.000.000 |
| 1182 | * 0000:0000:0000:0000:0000:0000:0000:0000 */ |
| 1183 | static char buf[50+1]; |
| 1184 | return inet_ntop(AF_INET6, addrp, buf, sizeof(buf)); |
| 1185 | } |
| 1186 | |
| 1187 | static const char *ip6addr_to_host(const struct in6_addr *addr) |
| 1188 | { |
| 1189 | static char hostname[NI_MAXHOST]; |
| 1190 | struct sockaddr_in6 saddr; |
| 1191 | int err; |
| 1192 | |
| 1193 | memset(&saddr, 0, sizeof(struct sockaddr_in6)); |
| 1194 | memcpy(&saddr.sin6_addr, addr, sizeof(*addr)); |
| 1195 | saddr.sin6_family = AF_INET6; |
| 1196 | |
| 1197 | err = getnameinfo((const void *)&saddr, sizeof(struct sockaddr_in6), |
| 1198 | hostname, sizeof(hostname) - 1, NULL, 0, 0); |
| 1199 | if (err != 0) { |
| 1200 | #ifdef DEBUG |
| 1201 | fprintf(stderr,"IP2Name: %s\n",gai_strerror(err)); |
| 1202 | #endif |
| 1203 | return NULL; |
| 1204 | } |
| 1205 | |
| 1206 | #ifdef DEBUG |
| 1207 | fprintf (stderr, "\naddr2host: %s\n", hostname); |
| 1208 | #endif |
| 1209 | return hostname; |
| 1210 | } |
| 1211 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 1212 | const char *xtables_ip6addr_to_anyname(const struct in6_addr *addr) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 1213 | { |
| 1214 | const char *name; |
| 1215 | |
| 1216 | if ((name = ip6addr_to_host(addr)) != NULL) |
| 1217 | return name; |
| 1218 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 1219 | return xtables_ip6addr_to_numeric(addr); |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | static int ip6addr_prefix_length(const struct in6_addr *k) |
| 1223 | { |
| 1224 | unsigned int bits = 0; |
| 1225 | uint32_t a, b, c, d; |
| 1226 | |
Jan Engelhardt | 4860781 | 2008-06-10 15:17:53 +0200 | [diff] [blame] | 1227 | a = ntohl(k->s6_addr32[0]); |
| 1228 | b = ntohl(k->s6_addr32[1]); |
| 1229 | c = ntohl(k->s6_addr32[2]); |
| 1230 | d = ntohl(k->s6_addr32[3]); |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 1231 | while (a & 0x80000000U) { |
| 1232 | ++bits; |
| 1233 | a <<= 1; |
| 1234 | a |= (b >> 31) & 1; |
| 1235 | b <<= 1; |
| 1236 | b |= (c >> 31) & 1; |
| 1237 | c <<= 1; |
| 1238 | c |= (d >> 31) & 1; |
| 1239 | d <<= 1; |
| 1240 | } |
| 1241 | if (a != 0 || b != 0 || c != 0 || d != 0) |
| 1242 | return -1; |
| 1243 | return bits; |
| 1244 | } |
| 1245 | |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 1246 | const char *xtables_ip6mask_to_numeric(const struct in6_addr *addrp) |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 1247 | { |
| 1248 | static char buf[50+2]; |
| 1249 | int l = ip6addr_prefix_length(addrp); |
| 1250 | |
| 1251 | if (l == -1) { |
| 1252 | strcpy(buf, "/"); |
Jan Engelhardt | e44ea7f | 2009-01-30 03:55:09 +0100 | [diff] [blame] | 1253 | strcat(buf, xtables_ip6addr_to_numeric(addrp)); |
Jan Engelhardt | 08b1616 | 2008-01-20 13:36:08 +0000 | [diff] [blame] | 1254 | return buf; |
| 1255 | } |
| 1256 | sprintf(buf, "/%d", l); |
| 1257 | return buf; |
| 1258 | } |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1259 | |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 1260 | struct in6_addr *xtables_numeric_to_ip6addr(const char *num) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1261 | { |
| 1262 | static struct in6_addr ap; |
| 1263 | int err; |
| 1264 | |
| 1265 | if ((err = inet_pton(AF_INET6, num, &ap)) == 1) |
| 1266 | return ≈ |
| 1267 | #ifdef DEBUG |
| 1268 | fprintf(stderr, "\nnumeric2addr: %d\n", err); |
| 1269 | #endif |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | |
| 1273 | static struct in6_addr * |
| 1274 | host_to_ip6addr(const char *name, unsigned int *naddr) |
| 1275 | { |
| 1276 | static struct in6_addr *addr; |
| 1277 | struct addrinfo hints; |
| 1278 | struct addrinfo *res; |
| 1279 | int err; |
| 1280 | |
| 1281 | memset(&hints, 0, sizeof(hints)); |
| 1282 | hints.ai_flags = AI_CANONNAME; |
| 1283 | hints.ai_family = AF_INET6; |
| 1284 | hints.ai_socktype = SOCK_RAW; |
| 1285 | hints.ai_protocol = IPPROTO_IPV6; |
| 1286 | hints.ai_next = NULL; |
| 1287 | |
| 1288 | *naddr = 0; |
| 1289 | if ((err = getaddrinfo(name, NULL, &hints, &res)) != 0) { |
| 1290 | #ifdef DEBUG |
| 1291 | fprintf(stderr,"Name2IP: %s\n",gai_strerror(err)); |
| 1292 | #endif |
| 1293 | return NULL; |
| 1294 | } else { |
| 1295 | if (res->ai_family != AF_INET6 || |
| 1296 | res->ai_addrlen != sizeof(struct sockaddr_in6)) |
| 1297 | return NULL; |
| 1298 | |
| 1299 | #ifdef DEBUG |
| 1300 | fprintf(stderr, "resolved: len=%d %s ", res->ai_addrlen, |
| 1301 | ip6addr_to_numeric(&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr)); |
| 1302 | #endif |
| 1303 | /* Get the first element of the address-chain */ |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 1304 | addr = xtables_malloc(sizeof(struct in6_addr)); |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1305 | memcpy(addr, &((const struct sockaddr_in6 *)res->ai_addr)->sin6_addr, |
| 1306 | sizeof(struct in6_addr)); |
| 1307 | freeaddrinfo(res); |
| 1308 | *naddr = 1; |
| 1309 | return addr; |
| 1310 | } |
| 1311 | |
| 1312 | return NULL; |
| 1313 | } |
| 1314 | |
| 1315 | static struct in6_addr *network_to_ip6addr(const char *name) |
| 1316 | { |
| 1317 | /* abort();*/ |
| 1318 | /* TODO: not implemented yet, but the exception breaks the |
| 1319 | * name resolvation */ |
| 1320 | return NULL; |
| 1321 | } |
| 1322 | |
| 1323 | static struct in6_addr * |
| 1324 | ip6parse_hostnetwork(const char *name, unsigned int *naddrs) |
| 1325 | { |
| 1326 | struct in6_addr *addrp, *addrptmp; |
| 1327 | |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 1328 | if ((addrptmp = xtables_numeric_to_ip6addr(name)) != NULL || |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1329 | (addrptmp = network_to_ip6addr(name)) != NULL) { |
Jan Engelhardt | 630ef48 | 2009-01-27 14:58:41 +0100 | [diff] [blame] | 1330 | addrp = xtables_malloc(sizeof(struct in6_addr)); |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1331 | memcpy(addrp, addrptmp, sizeof(*addrp)); |
| 1332 | *naddrs = 1; |
| 1333 | return addrp; |
| 1334 | } |
| 1335 | if ((addrp = host_to_ip6addr(name, naddrs)) != NULL) |
| 1336 | return addrp; |
| 1337 | |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 1338 | xt_params->exit_err(PARAMETER_PROBLEM, "host/network `%s' not found", name); |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | static struct in6_addr *parse_ip6mask(char *mask) |
| 1342 | { |
| 1343 | static struct in6_addr maskaddr; |
| 1344 | struct in6_addr *addrp; |
| 1345 | unsigned int bits; |
| 1346 | |
| 1347 | if (mask == NULL) { |
| 1348 | /* no mask at all defaults to 128 bits */ |
| 1349 | memset(&maskaddr, 0xff, sizeof maskaddr); |
| 1350 | return &maskaddr; |
| 1351 | } |
Jan Engelhardt | 1e01b0b | 2009-01-30 04:20:32 +0100 | [diff] [blame] | 1352 | if ((addrp = xtables_numeric_to_ip6addr(mask)) != NULL) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1353 | return addrp; |
Jan Engelhardt | 5f2922c | 2009-01-27 18:43:01 +0100 | [diff] [blame] | 1354 | if (!xtables_strtoui(mask, NULL, &bits, 0, 128)) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 1355 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1356 | "invalid mask `%s' specified", mask); |
| 1357 | if (bits != 0) { |
| 1358 | char *p = (void *)&maskaddr; |
| 1359 | memset(p, 0xff, bits / 8); |
| 1360 | memset(p + (bits / 8) + 1, 0, (128 - bits) / 8); |
| 1361 | p[bits/8] = 0xff << (8 - (bits & 7)); |
| 1362 | return &maskaddr; |
| 1363 | } |
| 1364 | |
| 1365 | memset(&maskaddr, 0, sizeof(maskaddr)); |
| 1366 | return &maskaddr; |
| 1367 | } |
| 1368 | |
Jan Engelhardt | a0baae8 | 2009-01-30 04:32:50 +0100 | [diff] [blame] | 1369 | void xtables_ip6parse_any(const char *name, struct in6_addr **addrpp, |
| 1370 | struct in6_addr *maskp, unsigned int *naddrs) |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1371 | { |
| 1372 | struct in6_addr *addrp; |
| 1373 | unsigned int i, j, k, n; |
| 1374 | char buf[256], *p; |
| 1375 | |
| 1376 | strncpy(buf, name, sizeof(buf) - 1); |
| 1377 | buf[sizeof(buf)-1] = '\0'; |
| 1378 | if ((p = strrchr(buf, '/')) != NULL) { |
| 1379 | *p = '\0'; |
| 1380 | addrp = parse_ip6mask(p + 1); |
| 1381 | } else { |
| 1382 | addrp = parse_ip6mask(NULL); |
| 1383 | } |
| 1384 | memcpy(maskp, addrp, sizeof(*maskp)); |
| 1385 | |
| 1386 | /* if a null mask is given, the name is ignored, like in "any/0" */ |
| 1387 | if (memcmp(maskp, &in6addr_any, sizeof(in6addr_any)) == 0) |
| 1388 | strcpy(buf, "::"); |
| 1389 | |
| 1390 | addrp = *addrpp = ip6parse_hostnetwork(buf, naddrs); |
| 1391 | n = *naddrs; |
| 1392 | for (i = 0, j = 0; i < n; ++i) { |
| 1393 | for (k = 0; k < 4; ++k) |
Yasuyuki Kozakai | 5a2208c | 2008-06-04 15:16:03 +0200 | [diff] [blame] | 1394 | addrp[j].s6_addr32[k] &= maskp->s6_addr32[k]; |
Jan Engelhardt | bd94384 | 2008-01-20 13:38:08 +0000 | [diff] [blame] | 1395 | ++j; |
| 1396 | for (k = 0; k < j - 1; ++k) |
| 1397 | if (IN6_ARE_ADDR_EQUAL(&addrp[k], &addrp[j - 1])) { |
| 1398 | --*naddrs; |
| 1399 | --j; |
| 1400 | break; |
| 1401 | } |
| 1402 | } |
| 1403 | } |
Max Kellermann | a5d0994 | 2008-01-29 13:44:34 +0000 | [diff] [blame] | 1404 | |
Jan Engelhardt | a0baae8 | 2009-01-30 04:32:50 +0100 | [diff] [blame] | 1405 | void xtables_save_string(const char *value) |
Max Kellermann | a5d0994 | 2008-01-29 13:44:34 +0000 | [diff] [blame] | 1406 | { |
| 1407 | static const char no_quote_chars[] = "_-0123456789" |
| 1408 | "abcdefghijklmnopqrstuvwxyz" |
| 1409 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
| 1410 | static const char escape_chars[] = "\"\\'"; |
| 1411 | size_t length; |
| 1412 | const char *p; |
| 1413 | |
| 1414 | length = strcspn(value, no_quote_chars); |
| 1415 | if (length > 0 && value[length] == 0) { |
| 1416 | /* no quoting required */ |
| 1417 | fputs(value, stdout); |
| 1418 | putchar(' '); |
| 1419 | } else { |
| 1420 | /* there is at least one dangerous character in the |
| 1421 | value, which we have to quote. Write double quotes |
| 1422 | around the value and escape special characters with |
| 1423 | a backslash */ |
| 1424 | putchar('"'); |
| 1425 | |
| 1426 | for (p = strpbrk(value, escape_chars); p != NULL; |
| 1427 | p = strpbrk(value, escape_chars)) { |
| 1428 | if (p > value) |
| 1429 | fwrite(value, 1, p - value, stdout); |
| 1430 | putchar('\\'); |
| 1431 | putchar(*p); |
| 1432 | value = p + 1; |
| 1433 | } |
| 1434 | |
| 1435 | /* print the rest and finish the double quoted |
| 1436 | string */ |
| 1437 | fputs(value, stdout); |
| 1438 | printf("\" "); |
| 1439 | } |
| 1440 | } |
Jan Engelhardt | 0f16c72 | 2009-01-30 04:55:38 +0100 | [diff] [blame] | 1441 | |
| 1442 | /** |
| 1443 | * Check for option-intrapositional negation. |
| 1444 | * Do not use in new code. |
| 1445 | */ |
| 1446 | int xtables_check_inverse(const char option[], int *invert, |
| 1447 | int *my_optind, int argc) |
| 1448 | { |
| 1449 | if (option && strcmp(option, "!") == 0) { |
| 1450 | fprintf(stderr, "Using intrapositioned negation " |
| 1451 | "(`--option ! this`) is deprecated in favor of " |
| 1452 | "extrapositioned (`! --option this`).\n"); |
| 1453 | |
| 1454 | if (*invert) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 1455 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | 0f16c72 | 2009-01-30 04:55:38 +0100 | [diff] [blame] | 1456 | "Multiple `!' flags not allowed"); |
| 1457 | *invert = true; |
| 1458 | if (my_optind != NULL) { |
| 1459 | ++*my_optind; |
| 1460 | if (argc && *my_optind > argc) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 1461 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | 0f16c72 | 2009-01-30 04:55:38 +0100 | [diff] [blame] | 1462 | "no argument following `!'"); |
| 1463 | } |
| 1464 | |
| 1465 | return true; |
| 1466 | } |
| 1467 | return false; |
| 1468 | } |
Jan Engelhardt | 1de7edf | 2009-01-30 05:38:11 +0100 | [diff] [blame] | 1469 | |
| 1470 | const struct xtables_pprot xtables_chain_protos[] = { |
| 1471 | {"tcp", IPPROTO_TCP}, |
| 1472 | {"sctp", IPPROTO_SCTP}, |
| 1473 | {"udp", IPPROTO_UDP}, |
| 1474 | {"udplite", IPPROTO_UDPLITE}, |
| 1475 | {"icmp", IPPROTO_ICMP}, |
| 1476 | {"icmpv6", IPPROTO_ICMPV6}, |
| 1477 | {"ipv6-icmp", IPPROTO_ICMPV6}, |
| 1478 | {"esp", IPPROTO_ESP}, |
| 1479 | {"ah", IPPROTO_AH}, |
| 1480 | {"ipv6-mh", IPPROTO_MH}, |
| 1481 | {"mh", IPPROTO_MH}, |
| 1482 | {"all", 0}, |
| 1483 | {NULL}, |
| 1484 | }; |
| 1485 | |
| 1486 | u_int16_t |
| 1487 | xtables_parse_protocol(const char *s) |
| 1488 | { |
| 1489 | unsigned int proto; |
| 1490 | |
| 1491 | if (!xtables_strtoui(s, NULL, &proto, 0, UINT8_MAX)) { |
| 1492 | struct protoent *pent; |
| 1493 | |
| 1494 | /* first deal with the special case of 'all' to prevent |
| 1495 | * people from being able to redefine 'all' in nsswitch |
| 1496 | * and/or provoke expensive [not working] ldap/nis/... |
| 1497 | * lookups */ |
| 1498 | if (!strcmp(s, "all")) |
| 1499 | return 0; |
| 1500 | |
| 1501 | if ((pent = getprotobyname(s))) |
| 1502 | proto = pent->p_proto; |
| 1503 | else { |
| 1504 | unsigned int i; |
| 1505 | for (i = 0; i < ARRAY_SIZE(xtables_chain_protos); ++i) { |
| 1506 | if (strcmp(s, xtables_chain_protos[i].name) == 0) { |
| 1507 | proto = xtables_chain_protos[i].num; |
| 1508 | break; |
| 1509 | } |
| 1510 | } |
| 1511 | if (i == ARRAY_SIZE(xtables_chain_protos)) |
Jamal Hadi Salim | 8b7baeb | 2009-02-11 13:05:43 +0100 | [diff] [blame] | 1512 | xt_params->exit_err(PARAMETER_PROBLEM, |
Jan Engelhardt | 1de7edf | 2009-01-30 05:38:11 +0100 | [diff] [blame] | 1513 | "unknown protocol `%s' specified", |
| 1514 | s); |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | return proto; |
| 1519 | } |