RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / include / linux / netfilter_ipv4 / ip_set_getport.h
blob18ed729422a9747b7c5b4ad900959060453ac147
1 #ifndef _IP_SET_GETPORT_H
2 #define _IP_SET_GETPORT_H
4 #ifdef __KERNEL__
6 #define INVALID_PORT (MAX_RANGE + 1)
8 /* We must handle non-linear skbs */
9 static inline ip_set_ip_t
10 get_port(const struct sk_buff *skb, const u_int32_t *flags)
12 struct iphdr *iph = ip_hdr(skb);
13 u_int16_t offset = ntohs(iph->frag_off) & IP_OFFSET;
14 switch (iph->protocol) {
15 case IPPROTO_TCP: {
16 struct tcphdr tcph;
18 /* See comments at tcp_match in ip_tables.c */
19 if (offset)
20 return INVALID_PORT;
22 if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &tcph, sizeof(tcph)) < 0)
23 /* No choice either */
24 return INVALID_PORT;
26 return ntohs(flags[0] & IPSET_SRC ?
27 tcph.source : tcph.dest);
29 case IPPROTO_UDP: {
30 struct udphdr udph;
32 if (offset)
33 return INVALID_PORT;
35 if (skb_copy_bits(skb, ip_hdr(skb)->ihl*4, &udph, sizeof(udph)) < 0)
36 /* No choice either */
37 return INVALID_PORT;
39 return ntohs(flags[0] & IPSET_SRC ?
40 udph.source : udph.dest);
42 default:
43 return INVALID_PORT;
46 #endif /* __KERNEL__ */
48 #endif /*_IP_SET_GETPORT_H*/