50#include <netlink/xfrm/template.h>
51#include <netlink-private/netlink.h>
53void xfrmnl_user_tmpl_free(
struct xfrmnl_user_tmpl* utmpl)
74 struct xfrmnl_user_tmpl* utmpl;
76 utmpl = calloc(1,
sizeof(
struct xfrmnl_user_tmpl));
80 nl_init_list_head(&utmpl->utmpl_list);
93 struct xfrmnl_user_tmpl*
new;
99 memcpy(
new, utmpl,
sizeof(
struct xfrmnl_user_tmpl));
112static const struct trans_tbl tmpl_modes[] = {
113 __ADD(XFRM_MODE_TRANSPORT, transport),
114 __ADD(XFRM_MODE_TUNNEL, tunnel),
115 __ADD(XFRM_MODE_ROUTEOPTIMIZATION, route optimization),
116 __ADD(XFRM_MODE_IN_TRIGGER, in trigger),
117 __ADD(XFRM_MODE_BEET, beet),
120char* xfrmnl_user_tmpl_mode2str(
int mode,
char *buf,
size_t len)
122 return __type2str (mode, buf, len, tmpl_modes, ARRAY_SIZE(tmpl_modes));
125int xfrmnl_user_tmpl_str2mode(
const char *name)
127 return __str2type (name, tmpl_modes, ARRAY_SIZE(tmpl_modes));
148 (a->id.spi != b->id.spi) ||
149 (a->id.proto && (a->id.proto != b->id.proto)) ||
151 (a->family != b->family) ||
152 (a->reqid != b->reqid) ||
153 (a->mode != b->mode) ||
154 (a->share != b->share) ||
155 (a->aalgos != b->aalgos) ||
156 (a->ealgos != b->ealgos) ||
157 (a->calgos != b->calgos))
164void xfrmnl_user_tmpl_dump(
struct xfrmnl_user_tmpl* tmpl,
struct nl_dump_params *p)
166 char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
169 nl_dump_line(p,
"\t\tsrc %s dst %s family: %s \n",
172 nl_af2str (tmpl->family, buf, 128));
173 nl_dump_line (p,
"\t\tprotocol: %s spi: 0x%x reqid: %u mode: %s\n",
174 nl_ip_proto2str (tmpl->id.proto, buf,
sizeof(buf)),
175 tmpl->id.spi, tmpl->reqid,
176 xfrmnl_user_tmpl_mode2str (tmpl->mode, buf, 128));
177 nl_dump_line (p,
"\t\tAuth Algo: 0x%x Crypto Algo: 0x%x Compr Algo: 0x%x\n",
178 tmpl->aalgos, tmpl->ealgos, tmpl->calgos);
189struct nl_addr* xfrmnl_user_tmpl_get_daddr (
struct xfrmnl_user_tmpl* utmpl)
191 return utmpl->id.daddr;
194int xfrmnl_user_tmpl_set_daddr (
struct xfrmnl_user_tmpl* utmpl,
struct nl_addr* addr)
200 utmpl->id.daddr = addr;
205int xfrmnl_user_tmpl_get_spi (
struct xfrmnl_user_tmpl* utmpl)
207 return utmpl->id.spi;
210int xfrmnl_user_tmpl_set_spi (
struct xfrmnl_user_tmpl* utmpl,
unsigned int spi)
217int xfrmnl_user_tmpl_get_proto (
struct xfrmnl_user_tmpl* utmpl)
219 return utmpl->id.proto;
222int xfrmnl_user_tmpl_set_proto (
struct xfrmnl_user_tmpl* utmpl,
unsigned int protocol)
224 utmpl->id.proto = protocol;
229int xfrmnl_user_tmpl_get_family(
struct xfrmnl_user_tmpl *utmpl)
231 return utmpl->family;
234int xfrmnl_user_tmpl_set_family(
struct xfrmnl_user_tmpl *utmpl,
unsigned int family)
236 utmpl->family = family;
241struct nl_addr* xfrmnl_user_tmpl_get_saddr (
struct xfrmnl_user_tmpl* utmpl)
246int xfrmnl_user_tmpl_set_saddr (
struct xfrmnl_user_tmpl* utmpl,
struct nl_addr* addr)
257int xfrmnl_user_tmpl_get_reqid (
struct xfrmnl_user_tmpl* utmpl)
262int xfrmnl_user_tmpl_set_reqid (
struct xfrmnl_user_tmpl* utmpl,
unsigned int reqid)
264 utmpl->reqid = reqid;
269int xfrmnl_user_tmpl_get_mode (
struct xfrmnl_user_tmpl* utmpl)
274int xfrmnl_user_tmpl_set_mode (
struct xfrmnl_user_tmpl* utmpl,
unsigned int mode)
281int xfrmnl_user_tmpl_get_share (
struct xfrmnl_user_tmpl* utmpl)
286int xfrmnl_user_tmpl_set_share (
struct xfrmnl_user_tmpl* utmpl,
unsigned int share)
288 utmpl->share = share;
293int xfrmnl_user_tmpl_get_optional (
struct xfrmnl_user_tmpl* utmpl)
295 return utmpl->optional;
298int xfrmnl_user_tmpl_set_optional (
struct xfrmnl_user_tmpl* utmpl,
unsigned int optional)
300 utmpl->optional = optional;
305int xfrmnl_user_tmpl_get_aalgos (
struct xfrmnl_user_tmpl* utmpl)
307 return utmpl->aalgos;
310int xfrmnl_user_tmpl_set_aalgos (
struct xfrmnl_user_tmpl* utmpl,
unsigned int aalgos)
312 utmpl->aalgos = aalgos;
317int xfrmnl_user_tmpl_get_ealgos (
struct xfrmnl_user_tmpl* utmpl)
319 return utmpl->ealgos;
322int xfrmnl_user_tmpl_set_ealgos (
struct xfrmnl_user_tmpl* utmpl,
unsigned int ealgos)
324 utmpl->ealgos = ealgos;
329int xfrmnl_user_tmpl_get_calgos (
struct xfrmnl_user_tmpl* utmpl)
331 return utmpl->calgos;
334int xfrmnl_user_tmpl_set_calgos (
struct xfrmnl_user_tmpl* utmpl,
unsigned int calgos)
336 utmpl->calgos = calgos;
struct xfrmnl_user_tmpl * xfrmnl_user_tmpl_clone(struct xfrmnl_user_tmpl *utmpl)
Clone existing user template object.
int xfrmnl_user_tmpl_cmp(struct xfrmnl_user_tmpl *a, struct xfrmnl_user_tmpl *b)
Compares two user template objects.
struct xfrmnl_user_tmpl * xfrmnl_user_tmpl_alloc()
Allocate new user template 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.