50#include <netlink/xfrm/selector.h>
51#include <netlink-private/netlink.h>
53static void sel_destroy(
struct xfrmnl_sel* sel)
60 fprintf(stderr,
"BUG: %s:%d\n", __FILE__, __LINE__);
80 struct xfrmnl_sel* sel;
82 sel = calloc(1,
sizeof(
struct xfrmnl_sel));
99 struct xfrmnl_sel*
new;
105 memcpy(
new, sel,
sizeof(
struct xfrmnl_sel));
119struct xfrmnl_sel* xfrmnl_sel_get(
struct xfrmnl_sel* sel)
126void xfrmnl_sel_put(
struct xfrmnl_sel* sel)
131 if (sel->refcnt == 1)
144 return sel->refcnt > 1;
167 ((a->sport & a->sport_mask) != (b->sport & b->sport_mask)) ||
168 ((a->dport & a->dport_mask) != (b->dport & b->dport_mask)) ||
169 (a->family != b->family) ||
170 (a->proto && (a->proto != b->proto)) ||
171 (a->ifindex && a->ifindex != b->ifindex) ||
172 (a->user != b->user))
179void xfrmnl_sel_dump(
struct xfrmnl_sel* sel,
struct nl_dump_params *p)
181 char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
184 nl_dump_line(p,
"\t\tsrc %s dst %s family: %s\n",
nl_addr2str(sel->saddr, src,
sizeof(src)),
185 nl_addr2str (sel->daddr, dst, sizeof (dst)), nl_af2str (sel->family, buf, 128));
186 nl_dump_line (p,
"\t\tsrc port/mask: %d/%d dst port/mask: %d/%d\n",
187 sel->dport, sel->dport_mask, sel->sport, sel->sport_mask);
188 nl_dump_line (p,
"\t\tprotocol: %s ifindex: %u user: %u\n",
189 nl_ip_proto2str (sel->proto, buf,
sizeof(buf)), sel->ifindex, sel->user);
201struct nl_addr* xfrmnl_sel_get_daddr (
struct xfrmnl_sel* sel)
206int xfrmnl_sel_set_daddr (
struct xfrmnl_sel* sel,
struct nl_addr* addr)
217struct nl_addr* xfrmnl_sel_get_saddr (
struct xfrmnl_sel* sel)
222int xfrmnl_sel_set_saddr (
struct xfrmnl_sel* sel,
struct nl_addr* addr)
233int xfrmnl_sel_get_dport (
struct xfrmnl_sel* sel)
238int xfrmnl_sel_set_dport (
struct xfrmnl_sel* sel,
unsigned int dport)
245int xfrmnl_sel_get_dportmask (
struct xfrmnl_sel* sel)
247 return sel->dport_mask;
250int xfrmnl_sel_set_dportmask (
struct xfrmnl_sel* sel,
unsigned int dport_mask)
252 sel->dport_mask = dport_mask;
257int xfrmnl_sel_get_sport (
struct xfrmnl_sel* sel)
262int xfrmnl_sel_set_sport (
struct xfrmnl_sel* sel,
unsigned int sport)
269int xfrmnl_sel_get_sportmask (
struct xfrmnl_sel* sel)
271 return sel->sport_mask;
274int xfrmnl_sel_set_sportmask (
struct xfrmnl_sel* sel,
unsigned int sport_mask)
276 sel->sport_mask = sport_mask;
281int xfrmnl_sel_get_family(
struct xfrmnl_sel *sel)
286int xfrmnl_sel_set_family(
struct xfrmnl_sel *sel,
unsigned int family)
288 sel->family = family;
293int xfrmnl_sel_get_prefixlen_d (
struct xfrmnl_sel* sel)
295 return sel->prefixlen_d;
298int xfrmnl_sel_set_prefixlen_d (
struct xfrmnl_sel* sel,
unsigned int prefixlen)
300 sel->prefixlen_d = prefixlen;
305int xfrmnl_sel_get_prefixlen_s (
struct xfrmnl_sel* sel)
307 return sel->prefixlen_s;
310int xfrmnl_sel_set_prefixlen_s (
struct xfrmnl_sel* sel,
unsigned int prefixlen)
312 sel->prefixlen_s = prefixlen;
317int xfrmnl_sel_get_proto (
struct xfrmnl_sel* sel)
322int xfrmnl_sel_set_proto (
struct xfrmnl_sel* sel,
unsigned int protocol)
324 sel->proto = protocol;
329int xfrmnl_sel_get_ifindex (
struct xfrmnl_sel* sel)
334int xfrmnl_sel_set_ifindex (
struct xfrmnl_sel* sel,
unsigned int ifindex)
336 sel->ifindex = ifindex;
341int xfrmnl_sel_get_userid (
struct xfrmnl_sel* sel)
346int xfrmnl_sel_set_userid (
struct xfrmnl_sel* sel,
unsigned int userid)
int xfrmnl_sel_shared(struct xfrmnl_sel *sel)
Check whether an selector object is shared.
int xfrmnl_sel_cmp(struct xfrmnl_sel *a, struct xfrmnl_sel *b)
Compares two selector objects.
struct xfrmnl_sel * xfrmnl_sel_alloc()
Allocate new selector object.
struct xfrmnl_sel * xfrmnl_sel_clone(struct xfrmnl_sel *sel)
Clone existing selector object.
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
int nl_addr_cmp_prefix(const struct nl_addr *a, const struct nl_addr *b)
Compare the prefix of two abstract addresses.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.