• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/iptables-1.4.12.1/extensions/

Lines Matching defs:*

0 #ifndef _LIBXT_SET_H
2 #define _LIBXT_SET_H
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <errno.h>
9 #ifdef DEBUG
10 #define DEBUGP(x, args...) fprintf(stderr, x , ## args)
11 #else
12 #define DEBUGP(x, args...)
13 #endif
15 static int
16 get_version(unsigned *version)
18 int res, sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
19 struct ip_set_req_version req_version;
20 socklen_t size = sizeof(req_version);
22 if (sockfd < 0)
23 xtables_error(OTHER_PROBLEM,
24 "Can't open socket to ipset.\n");
26 req_version.op = IP_SET_OP_VERSION;
27 res = getsockopt(sockfd, SOL_IP, SO_IP_SET, &req_version, &size);
28 if (res != 0)
29 xtables_error(OTHER_PROBLEM,
30 "Kernel module xt_set is not loaded in.\n");
32 *version = req_version.version;
34 return sockfd;
37 static void
38 get_set_byid(char *setname, ip_set_id_t idx)
40 struct ip_set_req_get_set req;
41 socklen_t size = sizeof(struct ip_set_req_get_set);
42 int res, sockfd;
44 sockfd = get_version(&req.version);
45 req.op = IP_SET_OP_GET_BYINDEX;
46 req.set.index = idx;
47 res = getsockopt(sockfd, SOL_IP, SO_IP_SET, &req, &size);
48 close(sockfd);
50 if (res != 0)
51 xtables_error(OTHER_PROBLEM,
52 "Problem when communicating with ipset, errno=%d.\n",
53 errno);
54 if (size != sizeof(struct ip_set_req_get_set))
55 xtables_error(OTHER_PROBLEM,
56 "Incorrect return size from kernel during ipset lookup, "
57 "(want %zu, got %zu)\n",
58 sizeof(struct ip_set_req_get_set), (size_t)size);
59 if (req.set.name[0] == '\0')
60 xtables_error(PARAMETER_PROBLEM,
61 "Set with index %i in kernel doesn't exist.\n", idx);
63 strncpy(setname, req.set.name, IPSET_MAXNAMELEN);
66 static void
67 get_set_byname(const char *setname, struct xt_set_info *info)
69 struct ip_set_req_get_set req;
70 socklen_t size = sizeof(struct ip_set_req_get_set);
71 int res, sockfd;
73 sockfd = get_version(&req.version);
74 req.op = IP_SET_OP_GET_BYNAME;
75 strncpy(req.set.name, setname, IPSET_MAXNAMELEN);
76 req.set.name[IPSET_MAXNAMELEN - 1] = '\0';
77 res = getsockopt(sockfd, SOL_IP, SO_IP_SET, &req, &size);
78 close(sockfd);
80 if (res != 0)
81 xtables_error(OTHER_PROBLEM,
82 "Problem when communicating with ipset, errno=%d.\n",
83 errno);
84 if (size != sizeof(struct ip_set_req_get_set))
85 xtables_error(OTHER_PROBLEM,
86 "Incorrect return size from kernel during ipset lookup, "
87 "(want %zu, got %zu)\n",
88 sizeof(struct ip_set_req_get_set), (size_t)size);
89 if (req.set.index == IPSET_INVALID_ID)
90 xtables_error(PARAMETER_PROBLEM,
91 "Set %s doesn't exist.\n", setname);
93 info->index = req.set.index;
96 static void
97 parse_dirs_v0(const char *opt_arg, struct xt_set_info_v0 *info)
99 char *saved = strdup(opt_arg);
100 char *ptr, *tmp = saved;
101 int i = 0;
103 while (i < (IPSET_DIM_MAX - 1) && tmp != NULL) {
104 ptr = strsep(&tmp, ",");
105 if (strncmp(ptr, "src", 3) == 0)
106 info->u.flags[i++] |= IPSET_SRC;
107 else if (strncmp(ptr, "dst", 3) == 0)
108 info->u.flags[i++] |= IPSET_DST;
109 else
110 xtables_error(PARAMETER_PROBLEM,
111 "You must spefify (the comma separated list of) 'src' or 'dst'.");
114 if (tmp)
115 xtables_error(PARAMETER_PROBLEM,
116 "Can't be more src/dst options than %i.",
117 IPSET_DIM_MAX);
119 free(saved);
122 static void
123 parse_dirs(const char *opt_arg, struct xt_set_info *info)
125 char *saved = strdup(opt_arg);
126 char *ptr, *tmp = saved;
128 while (info->dim < IPSET_DIM_MAX && tmp != NULL) {
129 info->dim++;
130 ptr = strsep(&tmp, ",");
131 if (strncmp(ptr, "src", 3) == 0)
132 info->flags |= (1 << info->dim);
133 else if (strncmp(ptr, "dst", 3) != 0)
134 xtables_error(PARAMETER_PROBLEM,
135 "You must spefify (the comma separated list of) 'src' or 'dst'.");
138 if (tmp)
139 xtables_error(PARAMETER_PROBLEM,
140 "Can't be more src/dst options than %i.",
141 IPSET_DIM_MAX);
143 free(saved);
146 #endif /*_LIBXT_SET_H*/