IPTables
view release on metacpan or search on metacpan
IPTables.xs view on Meta::CPAN
{
warn("Initial _init failed, trying to insmod\n");
iptables_insmod("ip_tables", modprobe);
*RETVAL = iptc_init(table);
}
if (!*RETVAL || RETVAL == NULL)
{
Safefree(RETVAL);
warn("Error initialising IPTables table '%s': '%s'\n", table, iptc_strerror(errno));
XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
int
iptc_builtin(h, chain)
iptc_handle_t * h;
const char * chain;
CODE:
RETVAL = iptc_builtin(chain, *h);
OUTPUT:
RETVAL
const char *
iptc_first_chain(h)
iptc_handle_t * h;
CODE:
if (h == NULL)
XSRETURN_UNDEF;
RETVAL = iptc_first_chain(h);
OUTPUT:
RETVAL
const char *
iptc_next_chain(h)
iptc_handle_t * h;
CODE:
if (h == NULL)
{
warn("handle has gone away\n");
XSRETURN_UNDEF;
}
RETVAL = iptc_next_chain(h);
OUTPUT:
RETVAL
void
iptc_get_policy(handle, chain)
const char * chain;
iptc_handle_t * handle;
PREINIT:
struct ipt_counters count;
char buf[64];
PPCODE:
if (!iptc_builtin(chain, *handle))
XSRETURN_UNDEF;
XPUSHs(sv_2mortal(newSVpv(iptc_get_policy(chain, &count, handle), 0)));
sprintf(buf, "%lu", count.pcnt);
XPUSHs(sv_2mortal(newSVpv(buf, strlen(buf))));
sprintf(buf, "%lu", count.bcnt);
XPUSHs(sv_2mortal(newSVpv(buf, strlen(buf))));
iptxs_entry *
iptc_first_rule(h, chain)
const char * chain;
iptc_handle_t * h;
PREINIT:
char *CLASS = "IPTables::Entry";
CODE:
RETVAL = (iptxs_entry *) safemalloc(sizeof(iptxs_entry));
if (RETVAL == NULL)
{
warn("Unable to allocate entry\n");
XSRETURN_UNDEF;
}
RETVAL->e = (entry_n *) iptc_first_rule(chain, h);
if (RETVAL->e == NULL)
{
Safefree(RETVAL);
XSRETURN_UNDEF;
}
strcpy(RETVAL->chain, chain);
RETVAL->h = h;
OUTPUT:
RETVAL
int
iptc_commit(h, table)
iptc_handle_t * h;
char *table;
CODE:
RETVAL = iptc_commit(h);
if (RETVAL == 0)
{
warn("Warning: commit failed\n");
XSRETURN_UNDEF;
}
if (h)
Safefree(h);
OUTPUT:
RETVAL
int
_print_num(num)
int num
CODE:
print_num(num, FMT_KILOMEGAGIGA);
RETVAL = 1;
IPTables.xs view on Meta::CPAN
optind--;
continue;
}
if (!m)
exit_error(PARAMETER_PROBLEM, "Unknown arg `%s'", newargv[optind-1]);
}
}
}
/* If they didn't specify a target, or it's a chain
name, use standard. */
if (!target && (strlen(jumpto) == 0 || iptc_is_chain(jumpto, *h)))
{
size_t size;
target = find_target(IPT_STANDARD_TARGET, LOAD_MUST_SUCCEED);
size = sizeof(struct ipt_entry_target) + target->size;
target->t = fw_calloc(1, size);
target->t->u.target_size = size;
strcpy(target->t->u.user.name, jumpto);
target->init(target->t, &fw.nfcache);
}
if (!target) {
/* it is no chain, and we can't load a plugin.
* We cannot know if the plugin is corrupt, non
* existant OR if the user just misspelled a
* chain. */
find_target(jumpto, LOAD_MUST_SUCCEED);
} else {
e = generate_entry(&fw, iptables_matches, target->t);
}
for (m = iptables_matches; m; m = m->next)
{
if (!m->used)
continue;
m->final_check(m->mflags);
}
if (target)
target->final_check(target->tflags);
/* printf("done, appending\n"); */
RETVAL &= append_entry(chain, e, nsaddrs, saddrs, ndaddrs, daddrs, OPT_VERBOSE, h);
/* printf("commiting rule\n"); */
RETVAL &= iptc_commit(h);
/* printf("commited\n"); */
OUTPUT:
RETVAL
void
get_match_options(name)
char * name;
PREINIT:
struct iptables_match *m;
unsigned int moo;
PPCODE:
m = find_match(name, TRY_LOAD);
if (m != NULL)
{
for (moo = 0; m->extra_opts[moo].name ; moo++)
{
XPUSHs(sv_2mortal(newSVpv(m->extra_opts[moo].name, strlen(m->extra_opts[moo].name))));
}
} else {
XPUSHs(sv_2mortal(newSVpv("-1-", strlen("-1-"))));
}
void
get_match_help(name)
char * name;
PREINIT:
struct iptables_match *m;
unsigned int moo;
PPCODE:
m = find_match(name, TRY_LOAD);
if (m != NULL)
{
m->help();
} else {
XPUSHs(sv_2mortal(newSVpv("-1-", strlen("-1-"))));
}
void
get_target_options(name)
char * name;
PREINIT:
struct iptables_target *m;
unsigned int moo;
PPCODE:
m = find_target(name, TRY_LOAD);
if (m != NULL)
{
for (moo = 0; m->extra_opts[moo].name ; moo++)
{
XPUSHs(sv_2mortal(newSVpv(m->extra_opts[moo].name, strlen(m->extra_opts[moo].name))));
}
} else {
XPUSHs(sv_2mortal(newSVpv("-1-", strlen("-1-"))));
}
void
get_target_help(name)
char * name;
PREINIT:
struct iptables_target *m;
unsigned int moo;
PPCODE:
m = find_target(name, TRY_LOAD);
if (m != NULL)
{
m->help();
} else {
XPUSHs(sv_2mortal(newSVpv("-1-", strlen("-1-"))));
}
MODULE = IPTables PACKAGE = IPTables::Entry
const char *
iniface(self)
iptxs_entry *self
PREINIT:
char buf[64];
CODE:
if (self->e->ip.iniface[0] != '\0')
strcpy(buf, self->e->ip.iniface);
else
strcpy(buf, "*");
RETVAL = buf;
OUTPUT:
RETVAL
const char *
outiface(self)
iptxs_entry *self
PREINIT:
char buf[64];
CODE:
if (self->e->ip.outiface[0] != '\0')
strcpy(buf, self->e->ip.outiface);
else
strcpy(buf, "*");
RETVAL = buf;
OUTPUT:
RETVAL
int
bytes(self, ...)
iptxs_entry *self
PREINIT:
char *count;
STRLEN n_a;
CODE:
if (items == 1)
{
if (self->e == NULL)
printf("Erk, e is undef!\n");
RETVAL = self->e->counters.bcnt;
} else {
count = (char *) SvPV(ST(1), n_a);
// self->e->counters.bcnt = atoll(count); // todo
RETVAL = 0;
}
( run in 1.521 second using v1.01-cache-2.11-cpan-71847e10f99 )