#include #include #include #include #include #include #include struct socket_testcase { int domain; int type; int protocol; /* 0 = valid file descriptor * -foo = error foo */ int expect; /* If non-zero, accept EAFNOSUPPORT to handle the case * of the protocol not being configured into the kernel. */ int nosupport_ok; }; static struct socket_testcase tests[] = { { AF_MAX, 0, 0, -EAFNOSUPPORT, 0 }, { AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 1 }, { AF_INET, SOCK_DGRAM, IPPROTO_TCP, -EPROTONOSUPPORT, 1 }, { AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, 1 }, { AF_INET, SOCK_STREAM, IPPROTO_UDP, -EPROTONOSUPPORT, 1 }, }; #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define ERR_STRING_SZ 64 static int run_tests(void) { char err_string1[ERR_STRING_SZ]; char err_string2[ERR_STRING_SZ]; int i, err; err = 0; for (i = 0; i < ARRAY_SIZE(tests); i++) { struct socket_testcase *s = &tests[i]; int fd; fd = socket(s->domain, s->type, s->protocol); if (fd < 0) { if (s->nosupport_ok && errno == EAFNOSUPPORT) continue; if (s->expect < 0 && errno == -s->expect) continue; strerror_r(-s->expect, err_string1, ERR_STRING_SZ); strerror_r(errno, err_string2, ERR_STRING_SZ); fprintf(stderr, "socket(%d, %d, %d) expected " "err (%s) got (%s)\n", s->domain, s->type, s->protocol, err_string1, err_string2); err = -1; break; } else { close(fd); if (s->expect < 0) { strerror_r(errno, err_string1, ERR_STRING_SZ); fprintf(stderr, "socket(%d, %d, %d) expected " "success got err (%s)\n", s->domain, s->type, s->protocol, err_string1); err = -1; break; } } } return err; } int main(void) { int err = run_tests(); return err; } et-next.git/tree/include/uapi/xen/evtchn.h?h=nds-private-remove&id=10435c1192d06bdb0bac7666452d8219d7e7c477'>treecommitdiff
diff options
context:
space:
mode:
authorFeng <fgao@ikuai8.com>2017-01-20 21:40:43 +0800
committerPablo Neira Ayuso <pablo@netfilter.org>2017-02-02 14:30:19 +0100
commit10435c1192d06bdb0bac7666452d8219d7e7c477 (patch)
tree93b76419142fe17b1d162d062c663297a3e8a965 /include/uapi/xen/evtchn.h
parent1a28ad74ebd8f9d3c7eae0d781f72a6d30545e17 (diff)
netfilter: nf_tables: Eliminate duplicated code in nf_tables_table_enable()
If something fails in nf_tables_table_enable(), it unregisters the chains. But the rollback code is the same as nf_tables_table_disable() almostly, except there is one counter check. Now create one wrapper function to eliminate the duplicated codes. Signed-off-by: Feng <fgao@ikuai8.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/uapi/xen/evtchn.h')