📄 ip_output_dummy.c
字号:
/* ip_output_dummy.c * linqianghe@163.com * 2006-09-09 */#include "myip.h"#include "dev_dummy.h"#include "log.h"#include "dummy_ipv4.h"#include "dst.h"#include "af_inet.h"#include <linux/netfilter.h>#include <linux/netfilter_ipv4.h>#include <net/ip.h>int ip_append_data_dummy( struct sock *sk, void *from, int length, int transhdrlen, struct rtable *rt, unsigned int flags ){ int ipheaderlen = 0; //the length of dummy ip header int hh_len = LL_RESERVED_SPACE(rt->u.dst.dev); int alloclen = length + transhdrlen + ipheaderlen + hh_len; struct sk_buff *skb; int err; PR_DEBUG( "copy the sending data to a sk_buff!, hh_len: %d\n", hh_len ); if( (skb = skb_peek_tail(&sk->sk_write_queue)) == NULL ){ if( atomic_read( &sk->sk_wmem_alloc ) <= 2 * sk->sk_sndbuf ) skb = sock_wmalloc(sk, alloclen + 15, 1, sk->sk_allocation); if (unlikely(skb == NULL)){ PR_ERR( "failed to allocate a sk_buff!\n"); err = -ENOBUFS; } } if (skb == NULL) goto error; err = -EFAULT; skb->nh.raw = skb_put( skb, alloclen ) + hh_len; if( skb_store_bits( skb, hh_len, DUMMY_HEADER, transhdrlen ) < 0 ){ PR_ERR( "copy DUMMY_HEADER to skb error!\n" ); goto error; } if( skb_store_bits( skb, hh_len + transhdrlen, ((struct iovec *)from)->iov_base, length ) < 0 ){ PR_ERR( "copy data to skb error!\n" ); goto error; } __skb_queue_tail( &sk->sk_write_queue, skb ); skb->dst = dst_clone( &rt->u.dst ); return 0;error: return err;}static inline int ip_finish_output2_dummy(struct sk_buff *skb){ struct dst_entry *dst = skb->dst; PR_DEBUG( "call skb->dst->neighbour->output!\n" ); return dst->neighbour->output(skb);}static inline int ip_finish_output_dummy( struct sk_buff *skb ){ PR_DEBUG( "call ip_finish_output2!\n" ); return ip_finish_output2_dummy( skb );}int ip_output_dummy( struct sk_buff *skb ){ struct net_device *dev = skb->dst->dev; PR_DEBUG( "call ip_finish_output!\n" ); skb->dev = dev; skb->protocol = htons(ETH_P_IP); return NF_HOOK_COND(MY_PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev, ip_finish_output_dummy, !(IPCB(skb)->flags & IPSKB_REROUTED));}int ip_push_pending_frames_dummy( struct sock *sk ){ struct sk_buff *skb; struct rtable *rt; int rc = 0; int err; PR_DEBUG( "start to send the ip packet out!\n" ); if( (skb = __skb_dequeue(&sk->sk_write_queue)) == NULL ) return rc; err = NF_HOOK( MY_PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dst->dev, mydst_output ); rt = skb->dst; ip_rt_put( rt ); skb->dst = NULL;/* if( err != 0 ){ PR_ERR( "unable to send out the packet!\n" ); dev_put( skb->dev ); skb_orphan( skb ); kfree( skb ); }*/ return err;}EXPORT_SYMBOL_GPL( ip_append_data_dummy );EXPORT_SYMBOL_GPL( ip_push_pending_frames_dummy );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -