~ubuntu-branches/ubuntu/raring/libvirt/raring

« back to all changes in this revision

Viewing changes to src/util/iptables.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-11-19 10:41:02 UTC
  • mfrom: (1.2.15) (223.1.2 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121119104102-l6ewdppikysbzztu
Tags: 1.0.0-0ubuntu2
debian/patches/add-armhf-sysinfo-infomration.patch: Disable
to fix FTBFS on arm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2007-2011 Red Hat, Inc.
 
2
 * Copyright (C) 2007-2012 Red Hat, Inc.
3
3
 *
4
4
 * This library is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU Lesser General Public
12
12
 * Lesser General Public License for more details.
13
13
 *
14
14
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this library; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
15
 * License along with this library.  If not, see
 
16
 * <http://www.gnu.org/licenses/>.
17
17
 *
18
18
 * Authors:
19
19
 *     Mark McLoughlin <markmc@redhat.com>
43
43
#include "memory.h"
44
44
#include "virterror_internal.h"
45
45
#include "logging.h"
 
46
#include "threads.h"
 
47
 
 
48
#if HAVE_FIREWALLD
 
49
static char *firewall_cmd_path = NULL;
 
50
 
 
51
static int
 
52
virIpTablesOnceInit(void)
 
53
{
 
54
    firewall_cmd_path = virFindFileInPath("firewall-cmd");
 
55
    if (!firewall_cmd_path) {
 
56
        VIR_INFO("firewall-cmd not found on system. "
 
57
                 "firewalld support disabled for iptables.");
 
58
    } else {
 
59
        virCommandPtr cmd = virCommandNew(firewall_cmd_path);
 
60
        int status;
 
61
 
 
62
        virCommandAddArgList(cmd, "--state", NULL);
 
63
        if (virCommandRun(cmd, &status) < 0 || status != 0) {
 
64
            VIR_INFO("firewall-cmd found but disabled for iptables");
 
65
            VIR_FREE(firewall_cmd_path);
 
66
            firewall_cmd_path = NULL;
 
67
        } else {
 
68
            VIR_INFO("using firewalld for iptables commands");
 
69
        }
 
70
        virCommandFree(cmd);
 
71
    }
 
72
    return 0;
 
73
}
 
74
 
 
75
VIR_ONCE_GLOBAL_INIT(virIpTables)
 
76
 
 
77
#endif
46
78
 
47
79
#define VIR_FROM_THIS VIR_FROM_NONE
48
 
#define iptablesError(code, ...)                                        \
49
 
    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,                 \
50
 
                         __FUNCTION__, __LINE__, __VA_ARGS__)
51
80
 
52
81
enum {
53
82
    ADD = 0,
104
133
{
105
134
    va_list args;
106
135
    int ret;
107
 
    virCommandPtr cmd;
 
136
    virCommandPtr cmd = NULL;
108
137
    const char *s;
109
138
 
110
 
    cmd = virCommandNew((family == AF_INET6)
 
139
#if HAVE_FIREWALLD
 
140
    virIpTablesInitialize();
 
141
    if (firewall_cmd_path) {
 
142
        cmd = virCommandNew(firewall_cmd_path);
 
143
        virCommandAddArgList(cmd, "--direct", "--passthrough",
 
144
                             (family == AF_INET6) ? "ipv6" : "ipv4", NULL);
 
145
    }
 
146
#endif
 
147
 
 
148
    if (cmd == NULL) {
 
149
        cmd = virCommandNew((family == AF_INET6)
111
150
                        ? IP6TABLES_PATH : IPTABLES_PATH);
 
151
    }
112
152
 
113
153
    virCommandAddArgList(cmd, "--table", rules->table,
114
154
                         action == ADD ? "--insert" : "--delete",
293
333
 
294
334
    if (!(VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET) ||
295
335
          VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET6))) {
296
 
        iptablesError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
297
 
                      _("Only IPv4 or IPv6 addresses can be used with iptables"));
 
336
        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
 
337
                       _("Only IPv4 or IPv6 addresses can be used with iptables"));
298
338
        return NULL;
299
339
    }
300
340
 
301
341
    if (virSocketAddrMaskByPrefix(netaddr, prefix, &network) < 0) {
302
 
        iptablesError(VIR_ERR_INTERNAL_ERROR, "%s",
303
 
                      _("Failure to mask address"));
 
342
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
343
                       _("Failure to mask address"));
304
344
        return NULL;
305
345
    }
306
346
 
763
803
 
764
804
    if (!VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET)) {
765
805
        /* Higher level code *should* guaranteee it's impossible to get here. */
766
 
        iptablesError(VIR_ERR_INTERNAL_ERROR,
767
 
                      _("Attempted to NAT '%s'. NAT is only supported for IPv4."),
768
 
                      networkstr);
 
806
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
807
                       _("Attempted to NAT '%s'. NAT is only supported for IPv4."),
 
808
                       networkstr);
769
809
        VIR_FREE(networkstr);
770
810
        return -1;
771
811
    }