1 typedef unsigned char __u8;
2 typedef unsigned short __u16;
3 typedef unsigned int __u32;
4 typedef unsigned long __kernel_size_t;
5 typedef __kernel_size_t size_t;
6 typedef __u8 uint8_t;
7 typedef __u16 __be16;
8 typedef __u32 __be32;
9 struct msghdr {
10 struct iovec * msg_iov;
11 unsigned msg_flags;
12 };
13 enum { IPPROTO_ICMP = 1 };
14 struct sk_buff { };
15 static inline __attribute__((always_inline)) struct dst_entry *
skb_dst(const struct sk_buff * skb)16 skb_dst(const struct sk_buff *skb)
17 {
18 };
19 enum nf_inet_hooks { NF_INET_LOCAL_OUT };
20 struct net_device {
21 unsigned mtu;
22 };
23 static inline __attribute__((always_inline)) int
NF_HOOK_THRESH(uint8_t pf,unsigned int hook,struct sk_buff * skb,struct net_device * in,struct net_device * out,int (* okfn)(struct sk_buff *),int thresh)24 NF_HOOK_THRESH(uint8_t pf, unsigned int hook, struct sk_buff *skb,
25 struct net_device *in, struct net_device *out,
26 int (*okfn)(struct sk_buff *), int thresh)
27 {
28 int ret = nf_hook_thresh(pf, hook, skb, in, out, okfn, thresh);
29 if (ret == 1)
30 ret = okfn(skb);
31 return ret;
32 }
33 static inline __attribute__((always_inline)) int
NF_HOOK(uint8_t pf,unsigned int hook,struct sk_buff * skb,struct net_device * in,struct net_device * out,int (* okfn)(struct sk_buff *))34 NF_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
35 struct net_device *in, struct net_device *out,
36 int (*okfn)(struct sk_buff *))
37 {
38 return NF_HOOK_THRESH(pf, hook, skb, in, out, okfn, (-((int)(~0U>>1)) - 1));
39 }
40 struct dst_entry {
41 struct net_device *dev;
42 int (*output)(struct sk_buff*);
43 };
dst_output(struct sk_buff * skb)44 static inline __attribute__((always_inline)) int dst_output(struct sk_buff *skb) {
45 return skb_dst(skb)->output(skb);
46 };
47 struct iphdr {
48 __u8 protocol;
49 };
50 struct inet_sock {
51 __be16 inet_dport;
52 __u8 recverr: 1, hdrincl: 1;
53 struct { } cork;
54 };
55 struct icmphdr {
56 __u8 type;
57 };
58 struct rtable {
59 union { struct dst_entry dst; } u;
60 __be32 rt_dst;
61 };
62 struct sock;
63 struct inet_sock *inet_sk (struct sock *);
64 struct net *sock_net (struct sock *);
65 void *skb_transport_header (struct sk_buff *);
raw_send_hdrinc(struct sock * sk,void * from,size_t length,struct rtable * rt,unsigned int flags)66 static int raw_send_hdrinc(struct sock *sk, void *from, size_t length,
67 struct rtable *rt, unsigned int flags)
68 {
69 struct inet_sock *inet = inet_sk(sk);
70 struct net *net = sock_net(sk);
71 struct iphdr *iph;
72 struct sk_buff *skb;
73 if (length > rt->u.dst.dev->mtu)
74 ip_local_error(sk, 90, rt->rt_dst, inet->inet_dport, rt->u.dst.dev->mtu);
75 if (flags&0x10)
76 goto out;
77 if (iph->protocol == IPPROTO_ICMP)
78 icmp_out_count(net, ((struct icmphdr *)skb_transport_header(skb))->type);
79 NF_HOOK(2, NF_INET_LOCAL_OUT, skb, ((void *)0), rt->u.dst.dev,
80 dst_output);
81 out:
82 while (0);
83 }
raw_sendmsg(struct sock * sk,struct msghdr * msg,size_t len)84 int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
85 {
86 raw_send_hdrinc(sk, msg->msg_iov, len, (void *)0, msg->msg_flags);
87 }
88