blob: 855f12a281549db80366ea5aba444c514a95f7df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#ifndef _IP_SET_GETPORT_H
#define _IP_SET_GETPORT_H
#ifdef __KERNEL__
#include <linux/netfilter_ipv6/ip6_tables.h>
#include <net/ip.h>
#define IPSET_INVALID_PORT 65536
/* We must handle non-linear skbs */
static uint32_t
get_port(uint8_t pf, const struct sk_buff *skb, const uint8_t *flags)
{
unsigned short protocol;
unsigned int protoff;
int fragoff;
switch (pf) {
case AF_INET: {
const struct iphdr *iph = ip_hdr(skb);
protocol = iph->protocol;
fragoff = ntohs(iph->frag_off) & IP_OFFSET;
protoff = ip_hdrlen(skb);
break;
}
case AF_INET6: {
int protohdr;
unsigned short frag_off;
protohdr = ipv6_find_hdr(skb, &protoff, -1, &frag_off);
if (protohdr < 0)
return IPSET_INVALID_PORT;
protocol = protohdr;
fragoff = frag_off;
break;
}
default:
return IPSET_INVALID_PORT;
}
/* See comments at tcp_match in ip_tables.c */
if (fragoff)
return IPSET_INVALID_PORT;
switch (protocol) {
case IPPROTO_TCP: {
struct tcphdr _tcph;
const struct tcphdr *th;
th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
if (th == NULL)
/* No choice either */
return IPSET_INVALID_PORT;
return flags[0] & IPSET_SRC ? th->source : th->dest;
}
case IPPROTO_UDP: {
struct udphdr _udph;
const struct udphdr *uh;
uh = skb_header_pointer(skb, protoff, sizeof(_udph), &_udph);
if (uh == NULL)
/* No choice either */
return IPSET_INVALID_PORT;
return flags[0] & IPSET_SRC ? uh->source : uh->dest;
}
default:
return IPSET_INVALID_PORT;
}
}
#endif /* __KERNEL__ */
#endif /*_IP_SET_GETPORT_H*/
|