Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Author: Paul.Russell@rustcorp.com.au and mneuling@radlogic.com.au |
| 3 | * |
| 4 | * Based on the ipchains code by Paul Russell and Michael Neuling |
| 5 | * |
Harald Welte | 10a907f | 2002-08-07 09:07:41 +0000 | [diff] [blame] | 6 | * (C) 2000-2002 by the netfilter coreteam <coreteam@netfilter.org>: |
| 7 | * Paul 'Rusty' Russell <rusty@rustcorp.com.au> |
| 8 | * Marc Boucher <marc+nf@mbsi.ca> |
| 9 | * James Morris <jmorris@intercode.com.au> |
| 10 | * Harald Welte <laforge@gnumonks.org> |
| 11 | * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> |
| 12 | * |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 13 | * iptables -- IP firewall administration for kernels with |
| 14 | * firewall table (aimed for the 2.3 kernels) |
| 15 | * |
| 16 | * See the accompanying manual page iptables(8) for information |
| 17 | * about proper usage of this program. |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License as published by |
| 21 | * the Free Software Foundation; either version 2 of the License, or |
| 22 | * (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 32 | */ |
| 33 | |
| 34 | #include <stdio.h> |
Rusty Russell | db78047 | 2000-12-19 05:17:50 +0000 | [diff] [blame] | 35 | #include <stdlib.h> |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 36 | #include <errno.h> |
Harald Welte | d8e6563 | 2001-01-05 15:20:07 +0000 | [diff] [blame] | 37 | #include <string.h> |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 38 | #include <iptables.h> |
Jan Engelhardt | 33690a1 | 2008-02-11 00:54:00 +0100 | [diff] [blame] | 39 | #include "iptables-multi.h" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 40 | |
Bastiaan Bakker | 4e3771f | 2004-06-25 11:18:57 +0000 | [diff] [blame] | 41 | #ifdef IPTABLES_MULTI |
| 42 | int |
| 43 | iptables_main(int argc, char *argv[]) |
| 44 | #else |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 45 | int |
| 46 | main(int argc, char *argv[]) |
Bastiaan Bakker | 4e3771f | 2004-06-25 11:18:57 +0000 | [diff] [blame] | 47 | #endif |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 48 | { |
| 49 | int ret; |
| 50 | char *table = "filter"; |
Rusty Russell | f7b062f | 2001-01-07 06:55:24 +0000 | [diff] [blame] | 51 | iptc_handle_t handle = NULL; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 52 | |
| 53 | program_name = "iptables"; |
Harald Welte | 80fe35d | 2002-05-29 13:08:15 +0000 | [diff] [blame] | 54 | program_version = IPTABLES_VERSION; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 55 | |
Jan Engelhardt | 21b41ee | 2008-02-11 01:02:00 +0100 | [diff] [blame] | 56 | lib_dir = getenv("XTABLES_LIBDIR"); |
| 57 | if (lib_dir == NULL) { |
| 58 | lib_dir = getenv("IPTABLES_LIB_DIR"); |
| 59 | if (lib_dir != NULL) |
| 60 | fprintf(stderr, "IPTABLES_LIB_DIR is deprecated\n"); |
| 61 | } |
| 62 | if (lib_dir == NULL) |
| 63 | lib_dir = XTABLES_LIBDIR; |
Martin Josefsson | 357d59d | 2004-12-27 19:49:28 +0000 | [diff] [blame] | 64 | |
Harald Welte | 3efb6ea | 2001-08-06 18:50:21 +0000 | [diff] [blame] | 65 | #ifdef NO_SHARED_LIBS |
| 66 | init_extensions(); |
| 67 | #endif |
| 68 | |
Rusty Russell | f7b062f | 2001-01-07 06:55:24 +0000 | [diff] [blame] | 69 | ret = do_command(argc, argv, &table, &handle); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 70 | if (ret) |
Rusty Russell | f7b062f | 2001-01-07 06:55:24 +0000 | [diff] [blame] | 71 | ret = iptc_commit(&handle); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 72 | |
Jesper Dangaard Brouer | 056564f | 2006-06-19 16:53:03 +0000 | [diff] [blame] | 73 | if (!ret) { |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 74 | fprintf(stderr, "iptables: %s\n", |
| 75 | iptc_strerror(errno)); |
Jesper Dangaard Brouer | 056564f | 2006-06-19 16:53:03 +0000 | [diff] [blame] | 76 | if (errno == EAGAIN) { |
| 77 | exit(RESOURCE_PROBLEM); |
| 78 | } |
| 79 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 80 | |
| 81 | exit(!ret); |
| 82 | } |