1 /* dnsmasq is Copyright (c) 2000-2013 Simon Kelley
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
23 static int gotit
= 0; /* yuck */
25 static int callback(enum nf_conntrack_msg_type type
, struct nf_conntrack
*ct
, void *data
);
27 int get_incoming_mark(union mysockaddr
*peer_addr
, struct all_addr
*local_addr
, int istcp
, unsigned int *markp
)
29 struct nf_conntrack
*ct
;
30 struct nfct_handle
*h
;
34 if ((ct
= nfct_new()))
36 nfct_set_attr_u8(ct
, ATTR_L4PROTO
, istcp
? IPPROTO_TCP
: IPPROTO_UDP
);
37 nfct_set_attr_u16(ct
, ATTR_PORT_DST
, htons(daemon
->port
));
40 if (peer_addr
->sa
.sa_family
== AF_INET6
)
42 nfct_set_attr_u8(ct
, ATTR_L3PROTO
, AF_INET6
);
43 nfct_set_attr(ct
, ATTR_IPV6_SRC
, peer_addr
->in6
.sin6_addr
.s6_addr
);
44 nfct_set_attr_u16(ct
, ATTR_PORT_SRC
, peer_addr
->in6
.sin6_port
);
45 nfct_set_attr(ct
, ATTR_IPV6_DST
, local_addr
->addr
.addr6
.s6_addr
);
50 nfct_set_attr_u8(ct
, ATTR_L3PROTO
, AF_INET
);
51 nfct_set_attr_u32(ct
, ATTR_IPV4_SRC
, peer_addr
->in
.sin_addr
.s_addr
);
52 nfct_set_attr_u16(ct
, ATTR_PORT_SRC
, peer_addr
->in
.sin_port
);
53 nfct_set_attr_u32(ct
, ATTR_IPV4_DST
, local_addr
->addr
.addr4
.s_addr
);
57 if ((h
= nfct_open(CONNTRACK
, 0)))
59 nfct_callback_register(h
, NFCT_T_ALL
, callback
, (void *)markp
);
60 if (nfct_query(h
, NFCT_Q_GET
, ct
) == -1)
62 static int warned
= 0;
65 my_syslog(LOG_ERR
, _("Conntrack connection mark retrieval failed: %s"), strerror(errno
));
77 static int callback(enum nf_conntrack_msg_type type
, struct nf_conntrack
*ct
, void *data
)
79 unsigned int *ret
= (unsigned int *)data
;
80 *ret
= nfct_get_attr_u32(ct
, ATTR_MARK
);
81 (void)type
; /* eliminate warning */
84 return NFCT_CB_CONTINUE
;