toolchain: switch kernel 2.4 builds to gcc 4.2.4
[tomato.git] / tools / brcm / K24 / hndtools-mipsel-uclibc-4.1.2 / include / linux / netfilter_ipv4 / ip_set_getport.h
blob9e322bfaced3f05cf09d99b915437fd948a92f45
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, 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 & 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 & IPSET_SRC ?
40 udph.source : udph.dest);
42 default:
43 return INVALID_PORT;
46 #endif /* __KERNEL__ */
48 #endif /*_IP_SET_GETPORT_H*/