📄 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"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 alloclen = length + transhdrlen + ipheaderlen; struct sk_buff *skb; int err; PR_DEBUG( "copy the sending data to a sk_buff!\n" ); 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_put( skb, alloclen ); if( skb_store_bits( skb, 0, DUMMY_HEADER, transhdrlen ) < 0 ){ PR_ERR( "copy DUMMY_HEADER to skb error!\n" ); goto error; } if( skb_store_bits( skb, transhdrlen, ((struct iovec *)from)->iov_base, length ) < 0 ){ PR_ERR( "copy data to skb error!\n" ); goto error; } err = -ENODEV; if( (skb->dev = dev_get_by_name( "mylo" )) == NULL ) goto error; __skb_queue_tail( &sk->sk_write_queue, skb ); return 0;error: return err;}static inline int ip_finish_output2_dummy(struct sk_buff *skb){ PR_DEBUG( "call skb->dst->neighbour->output!\n" ); return neigh_resolve_output_dummy( 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 ){ PR_DEBUG( "call ip_finish_output!\n" ); skb->protocol = htons(ETH_P_IP); return ip_finish_output_dummy( skb );}static inline int dst_output_dummy(struct sk_buff *skb){ PR_DEBUG( "call the function skb->dst->output!\n" ); return ip_output_dummy( skb );}int ip_push_pending_frames_dummy( struct sock *sk ){ struct sk_buff *skb; int rc = 0; PR_DEBUG( "start to send the ip packet out!\n" ); if( (skb = __skb_dequeue(&sk->sk_write_queue)) == NULL ) return rc; if( (rc = dst_output_dummy( skb )) != 0 ){ PR_ERR( "unable to send out the packet!\n" ); dev_put( skb->dev ); skb_orphan( skb ); kfree( skb ); } return rc;}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 + -