本文整理汇总了C++中__constant_htons函数的典型用法代码示例。如果您正苦于以下问题:C++ __constant_htons函数的具体用法?C++ __constant_htons怎么用?C++ __constant_htons使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了__constant_htons函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ktrcv
ktrcv(iskb);
if ((oskb = skb_dequeue(&skb_outq)))
dev_queue_xmit(oskb);
} while (iskb || oskb);
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&ktwaitq, &wait);
schedule();
remove_wait_queue(&ktwaitq, &wait);
} while (!kthread_should_stop());
__set_current_state(TASK_RUNNING);
complete(&ktrendez);
return 0;
}
static struct packet_type pt = {
.type = __constant_htons(ETH_P_AOE),
.func = rcv,
};
static int __init kvblade_module_init(void)
{
skb_queue_head_init(&skb_outq);
skb_queue_head_init(&skb_inq);
spin_lock_init(&lock);
init_completion(&ktrendez);
init_waitqueue_head(&ktwaitq);
task = kthread_run(kthread, NULL, "kvblade");
if (task == NULL || IS_ERR(task))
示例2: __skb_flow_dissect
//.........这里部分代码省略.........
}
case htons(ETH_P_8021AD):
case htons(ETH_P_8021Q): {
const struct vlan_hdr *vlan;
struct vlan_hdr _vlan;
vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan);
if (!vlan)
return false;
proto = vlan->h_vlan_encapsulated_proto;
nhoff += sizeof(*vlan);
goto again;
}
case htons(ETH_P_PPP_SES): {
struct {
struct pppoe_hdr hdr;
__be16 proto;
} *hdr, _hdr;
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr)
return false;
proto = hdr->proto;
nhoff += PPPOE_SES_HLEN;
switch (proto) {
case htons(PPP_IP):
goto ip;
case htons(PPP_IPV6):
goto ipv6;
default:
return false;
}
}
case __constant_htons(ETH_P_MAP): {
struct {
struct rmnet_map_header_s map;
uint8_t proto;
} *map, _map;
unsigned int maplen;
map = skb_header_pointer(skb, nhoff, sizeof(_map), &_map);
if (!map)
return false;
/* Is MAP command? */
if (map->map.cd_bit)
return false;
/* Is aggregated frame? */
maplen = ntohs(map->map.pkt_len);
maplen += map->map.pad_len;
maplen += sizeof(struct rmnet_map_header_s);
if (maplen < skb->len)
return false;
nhoff += sizeof(struct rmnet_map_header_s);
switch (map->proto & RMNET_IP_VER_MASK) {
case RMNET_IPV4:
proto = htons(ETH_P_IP);
goto ip;
case RMNET_IPV6:
proto = htons(ETH_P_IPV6);
goto ipv6;
default:
return false;
}
示例3: __fsm_dev_init
void __fsm_dev_init(struct net_device *dev);
int __fsm_dev_open(struct net_device *dev);
int __fsm_dev_stop(struct net_device *dev);
int __fsm_dev_set_config(struct net_device *dev, struct ifmap *p_ifmap);
int __fsm_dev_recv(struct sk_buff *skb ,struct net_device *dev1, struct packet_type *pktype, struct net_device *dev2);
int __fsm_dev_tx(struct sk_buff *skb, struct net_device *dev);
int __fsm_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
struct net_device_stats* __fsm_dev_get_stats(struct net_device *dev);
void __fsm_dev_tx_timeout(struct net_device *p_net_device);
void __fsm_dev_init(struct net_device *dev);
/*---------------------------------------------------------------------------*/
/* this is used for register the special packet type that processed by DYS */
struct packet_type pk_t = {
.type = __constant_htons(MY_PROTOCOL),
.func = __fsm_dev_recv,
};
static const struct net_device_ops fsm_netdev_ops = {
.ndo_open = __fsm_dev_open,
.ndo_stop = __fsm_dev_stop,
.ndo_start_xmit = __fsm_dev_tx,
.ndo_get_stats = __fsm_dev_get_stats,
.ndo_do_ioctl = __fsm_dev_ioctl,
.ndo_set_config = __fsm_dev_set_config,
.ndo_tx_timeout = __fsm_dev_tx_timeout,
};
typedef struct fsm_priv
{
示例4: llc_sap_close
* @sap: SAP to be closed.
*
* Close interface function to upper layer. Each one who wants to
* close an open SAP (for example NetBEUI) should call this function.
* Removes this sap from the list of saps in the station and then
* frees the memory for this sap.
*/
void llc_sap_close(struct llc_sap *sap)
{
WARN_ON(!hlist_empty(&sap->sk_list.list));
llc_del_sap(sap);
kfree(sap);
}
static struct packet_type llc_packet_type = {
.type = __constant_htons(ETH_P_802_2),
.func = llc_rcv,
};
static struct packet_type llc_tr_packet_type = {
.type = __constant_htons(ETH_P_TR_802_2),
.func = llc_rcv,
};
static int __init llc_init(void)
{
struct net_device *dev;
dev = first_net_device(&init_net);
if (dev != NULL)
dev = next_net_device(dev);
示例5: ip_hdr
/**
根据tcp数据生成数据包
根据tcp数据,生成数据包,并填充 mac/ip/tcp 头部信息
@param skb 原始的sk_buff结构地址
@param names 网卡名称结构首地址
@param num 网卡个数
@param tcpdata tcp数据地址
@param tcpdatalen tcp数据长度
@return 成功返回数据包地址,失败返回NULL。
*/
struct sk_buff *pkg_skbuff_generate(struct sk_buff *skb, struct client_nicname *names, int num, char *tcpdata, int tcpdatalen)
{
struct sk_buff *new_skb = NULL;
struct net_device *dev = NULL;
struct iphdr *iph = NULL,*new_iph = NULL;
struct tcphdr *tcph = NULL,*new_tcph = NULL;
struct ethhdr *ethdr = NULL;
char *newpdata = NULL;
unsigned char * mac_header_addr = NULL;
int i = 0;
if(!skb || !names)
{
goto out;
}
iph = ip_hdr(skb);
if(iph == NULL)
{
goto out;
}
tcph = (struct tcphdr *)((char *)iph + iph->ihl*4);
if(tcph == NULL)
{
goto out;
}
ethdr = eth_hdr(skb);
if(ethdr == NULL)
{
goto out;
}
for (i=0; names[i].index != -1; i++)
{
#if (LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 24))//不确定版本号是否应该更早
dev = dev_get_by_name(names[i].name);
#else
dev = dev_get_by_name(&init_net, names[i].name);
#endif
if (dev != NULL)
break;
}
if (dev == NULL)
{
goto out;
}
new_skb = alloc_skb(tcpdatalen + iph->ihl*4 + tcph->doff*4 + 14, GFP_ATOMIC);
if(new_skb == NULL)
{
goto out;
}
#if (LINUX_VERSION_CODE < KERNEL_VERSION (3, 11, 0))
new_skb->mac_header = new_skb->data;
skb_reserve(new_skb,14);
new_skb->transport_header = new_skb->data;
new_skb->network_header = new_skb->data;
//get_route_mac(iph->saddr, iph->daddr);
memcpy(&new_skb->mac_header[0], ethdr->h_source, 6);
memcpy(&new_skb->mac_header[6], ethdr->h_dest, 6);
new_skb->mac_header[12] = 0x08;
new_skb->mac_header[13] = 0x00;
#else
skb_reset_mac_header(new_skb);
skb_reserve(new_skb,14);
skb_reset_transport_header(new_skb);
skb_reset_network_header(new_skb);
mac_header_addr=skb_mac_header(new_skb);
if(mac_header_addr==NULL)
{
printk("Can't get header address!\n");
goto out;
}
//get_route_mac(iph->saddr, iph->daddr);
memcpy(mac_header_addr, ethdr->h_source, 6);
memcpy(mac_header_addr+6, ethdr->h_dest, 6);
mac_header_addr[12] = 0x08;
mac_header_addr[13] = 0x00;
#endif
skb_put(new_skb, iph->ihl*4 + tcph->doff*4);
new_skb->mac_len = 14;
new_skb->dev = dev;
new_skb->pkt_type = PACKET_OTHERHOST;
new_skb->protocol = __constant_htons(ETH_P_IP);
new_skb->ip_summed = CHECKSUM_NONE;
new_skb->priority = 0;
/*
//.........这里部分代码省略.........
示例6: vlan_skb_recv
//.........这里部分代码省略.........
// stats->broadcast ++; // no such counter :-(
break;
case PACKET_MULTICAST:
stats->multicast++;
break;
case PACKET_OTHERHOST:
/* Our lower layer thinks this is not local, let's make sure.
* This allows the VLAN to have a different MAC than the underlying
* device, and still route correctly.
*/
if (memcmp(skb->mac.ethernet->h_dest, skb->dev->dev_addr, ETH_ALEN) == 0) {
/* It is for our (changed) MAC-address! */
skb->pkt_type = PACKET_HOST;
}
break;
default:
break;
};
/* Was a VLAN packet, grab the encapsulated protocol, which the layer
* three protocols care about.
*/
/* proto = get_unaligned(&vhdr->h_vlan_encapsulated_proto); */
proto = vhdr->h_vlan_encapsulated_proto;
skb->protocol = proto;
if (ntohs(proto) >= 1536) {
/* place it back on the queue to be handled by
* true layer 3 protocols.
*/
/* See if we are configured to re-write the VLAN header
* to make it look like ethernet...
*/
skb = vlan_check_reorder_header(skb);
/* Can be null if skb-clone fails when re-ordering */
if (skb) {
netif_rx(skb);
} else {
/* TODO: Add a more specific counter here. */
stats->rx_errors++;
}
spin_unlock_bh(&vlan_group_lock);
return 0;
}
rawp = skb->data;
/*
* This is a magic hack to spot IPX packets. Older Novell breaks
* the protocol design and runs IPX over 802.3 without an 802.2 LLC
* layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
* won't work for fault tolerant netware but does for the rest.
*/
if (*(unsigned short *)rawp == 0xFFFF) {
skb->protocol = __constant_htons(ETH_P_802_3);
/* place it back on the queue to be handled by true layer 3 protocols.
*/
/* See if we are configured to re-write the VLAN header
* to make it look like ethernet...
*/
skb = vlan_check_reorder_header(skb);
/* Can be null if skb-clone fails when re-ordering */
if (skb) {
netif_rx(skb);
} else {
/* TODO: Add a more specific counter here. */
stats->rx_errors++;
}
spin_unlock_bh(&vlan_group_lock);
return 0;
}
/*
* Real 802.2 LLC
*/
skb->protocol = __constant_htons(ETH_P_802_2);
/* place it back on the queue to be handled by upper layer protocols.
*/
/* See if we are configured to re-write the VLAN header
* to make it look like ethernet...
*/
skb = vlan_check_reorder_header(skb);
/* Can be null if skb-clone fails when re-ordering */
if (skb) {
netif_rx(skb);
} else {
/* TODO: Add a more specific counter here. */
stats->rx_errors++;
}
spin_unlock_bh(&vlan_group_lock);
return 0;
}
示例7: in_dev_put
do {
in_dev_put(xdst->u.rt.idev);
xdst->u.rt.idev = loopback_idev;
in_dev_hold(loopback_idev);
xdst = (struct xfrm_dst *)xdst->u.dst.child;
} while (xdst->u.dst.xfrm);
__in_dev_put(loopback_idev);
}
xfrm_dst_ifdown(dst, dev);
}
static struct dst_ops xfrm4_dst_ops = {
.family = AF_INET,
.protocol = __constant_htons(ETH_P_IP),
.gc = xfrm4_garbage_collect,
.update_pmtu = xfrm4_update_pmtu,
.destroy = xfrm4_dst_destroy,
.ifdown = xfrm4_dst_ifdown,
.gc_thresh = 1024,
.entry_size = sizeof(struct xfrm_dst),
};
static struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
.family = AF_INET,
.dst_ops = &xfrm4_dst_ops,
.dst_lookup = xfrm4_dst_lookup,
.get_saddr = xfrm4_get_saddr,
.find_bundle = __xfrm4_find_bundle,
.bundle_create = __xfrm4_bundle_create,
示例8: MODULE_DESCRIPTION
MODULE_DESCRIPTION("ltemac kernel module");
MODULE_AUTHOR("");
MODULE_LICENSE("GPL");
#include "../fsm/fsmdec.h"
#include "../lte_system.h"
#include "../debug.h"
#include "virtual_srio.h"
/* this is used for register the special packet type that processed by DYS */
struct packet_type pk_t = {
.type = __constant_htons(DEV_PROTO_SRIO),
.func = fsm_dev_recv,
};
static const struct net_device_ops srio_netdev_ops = {
.ndo_open = fsm_dev_open,
.ndo_stop = fsm_dev_stop,
.ndo_start_xmit = fsm_dev_tx,
.ndo_get_stats = fsm_dev_get_stats,
.ndo_do_ioctl = fsm_dev_ioctl,
.ndo_set_config = fsm_dev_set_config,
.ndo_tx_timeout = fsm_dev_tx_timeout,
};
示例9: rt_arp_rcv
/***
* arp_rcv: Receive an arp request by the device layer.
*/
int rt_arp_rcv(struct rtskb *skb, struct rtpacket_type *pt)
{
struct rtnet_device *rtdev = skb->rtdev;
struct arphdr *arp = skb->nh.arph;
unsigned char *arp_ptr= (unsigned char *)(arp+1);
unsigned char *sha, *tha;
u32 sip, tip;
u16 dev_type = rtdev->type;
/*
* The hardware length of the packet should match the hardware length
* of the device. Similarly, the hardware types should match. The
* device should be ARP-able. Also, if pln is not 4, then the lookup
* is not from an IP number. We can't currently handle this, so toss
* it.
*/
if ((arp->ar_hln != rtdev->addr_len) ||
(rtdev->flags & IFF_NOARP) ||
(skb->pkt_type == PACKET_OTHERHOST) ||
(skb->pkt_type == PACKET_LOOPBACK) ||
(arp->ar_pln != 4))
goto out;
switch (dev_type) {
default:
if ((arp->ar_pro != __constant_htons(ETH_P_IP)) &&
(htons(dev_type) != arp->ar_hrd))
goto out;
break;
case ARPHRD_ETHER:
/*
* ETHERNET devices will accept ARP hardware types of either
* 1 (Ethernet) or 6 (IEEE 802.2).
*/
if ((arp->ar_hrd != __constant_htons(ARPHRD_ETHER)) &&
(arp->ar_hrd != __constant_htons(ARPHRD_IEEE802))) {
goto out;
}
if (arp->ar_pro != __constant_htons(ETH_P_IP)) {
goto out;
}
break;
}
/* Understand only these message types */
if ((arp->ar_op != __constant_htons(ARPOP_REPLY)) &&
(arp->ar_op != __constant_htons(ARPOP_REQUEST)))
goto out;
/*
* Extract fields
*/
sha=arp_ptr;
arp_ptr += rtdev->addr_len;
memcpy(&sip, arp_ptr, 4);
arp_ptr += 4;
tha=arp_ptr;
arp_ptr += rtdev->addr_len;
memcpy(&tip, arp_ptr, 4);
/* process only requests/replies directed to us */
if (tip == rtdev->local_ip) {
rt_ip_route_add_host(sip, sha, rtdev);
if (arp->ar_op == __constant_htons(ARPOP_REQUEST))
rt_arp_send(ARPOP_REPLY, ETH_P_ARP, sip, rtdev, tip, sha,
rtdev->dev_addr, sha);
}
out:
kfree_rtskb(skb);
return 0;
}
示例10: rt_arp_send
/***
* arp_send: Create and send an arp packet. If (dest_hw == NULL),
* we create a broadcast message.
*/
void rt_arp_send(int type,
int ptype,
u32 dest_ip,
struct rtnet_device *rtdev,
u32 src_ip,
unsigned char *dest_hw,
unsigned char *src_hw,
unsigned char *target_hw)
{
struct rtskb *skb;
struct arphdr *arp;
unsigned char *arp_ptr;
if (rtdev->flags & IFF_NOARP)
return;
if (!(skb=alloc_rtskb(sizeof(struct arphdr) + 2*(rtdev->addr_len+4) +
rtdev->hard_header_len+15, &global_pool)))
return;
rtskb_reserve(skb, (rtdev->hard_header_len+15)&~15);
skb->nh.raw = skb->data;
arp = (struct arphdr *)rtskb_put(skb, sizeof(struct arphdr) +
2*(rtdev->addr_len+4));
skb->rtdev = rtdev;
skb->protocol = __constant_htons (ETH_P_ARP);
skb->priority = RT_ARP_SKB_PRIO;
if (src_hw == NULL)
src_hw = rtdev->dev_addr;
if (dest_hw == NULL)
dest_hw = rtdev->broadcast;
/*
* Fill the device header for the ARP frame
*/
if (rtdev->hard_header &&
(rtdev->hard_header(skb,rtdev,ptype,dest_hw,src_hw,skb->len) < 0))
goto out;
arp->ar_hrd = htons(rtdev->type);
arp->ar_pro = __constant_htons(ETH_P_IP);
arp->ar_hln = rtdev->addr_len;
arp->ar_pln = 4;
arp->ar_op = htons(type);
arp_ptr=(unsigned char *)(arp+1);
memcpy(arp_ptr, src_hw, rtdev->addr_len);
arp_ptr+=rtdev->addr_len;
memcpy(arp_ptr, &src_ip,4);
arp_ptr+=4;
if (target_hw != NULL)
memcpy(arp_ptr, target_hw, rtdev->addr_len);
else
memset(arp_ptr, 0, rtdev->addr_len);
arp_ptr+=rtdev->addr_len;
memcpy(arp_ptr, &dest_ip, 4);
/* send the frame */
rtdev_xmit(skb);
return;
out:
kfree_rtskb(skb);
}
示例11: vnet_start_xmit
static int vnet_start_xmit(struct sk_buff *skb, struct net_device *net)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
struct pdp_info *dev = (struct pdp_info *)net->ml_priv;
#else
struct pdp_info *dev = (struct pdp_info *)net->priv;
#endif
//printk("============> vnet_start_xmit() Called .. !!\n");
#ifdef USE_LOOPBACK_PING
int ret;
struct sk_buff *skb2;
struct icmphdr *icmph;
struct iphdr *iph;
#endif
#ifdef USE_LOOPBACK_PING
dev->vn_dev.stats.tx_bytes += skb->len;
dev->vn_dev.stats.tx_packets++;
skb2 = alloc_skb(skb->len, GFP_ATOMIC);
if (skb2 == NULL) {
DPRINTK(1, "alloc_skb() failed\n");
dev_kfree_skb_any(skb);
return -ENOMEM;
}
memcpy(skb2->data, skb->data, skb->len);
skb_put(skb2, skb->len);
dev_kfree_skb_any(skb);
icmph = (struct icmphdr *)(skb2->data + sizeof(struct iphdr));
iph = (struct iphdr *)skb2->data;
icmph->type = __constant_htons(ICMP_ECHOREPLY);
ret = iph->daddr;
iph->daddr = iph->saddr;
iph->saddr = ret;
iph->check = 0;
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
skb2->dev = net;
skb2->protocol = __constant_htons(ETH_P_IP);
netif_rx(skb2);
dev->vn_dev.stats.rx_packets++;
dev->vn_dev.stats.rx_bytes += skb->len;
#else
if (vnet_start_xmit_flag != 0) {
return NETDEV_TX_BUSY;
}
vnet_start_xmit_flag = 1;
workqueue_data = (unsigned long)skb;
PREPARE_WORK(&dev->vn_dev.xmit_task,vnet_defer_xmit);
schedule_work(&dev->vn_dev.xmit_task);
netif_stop_queue(net);
#endif
return 0;
}
示例12: module_param_named
/*
* Module parameters
*/
#ifdef CONFIG_IRDA_DEBUG
unsigned int irda_debug = IRDA_DEBUG_LEVEL;
module_param_named(debug, irda_debug, uint, 0);
MODULE_PARM_DESC(debug, "IRDA debugging level");
EXPORT_SYMBOL(irda_debug);
#endif
/* Packet type handler.
* Tell the kernel how IrDA packets should be handled.
*/
static struct packet_type irda_packet_type = {
.type = __constant_htons(ETH_P_IRDA),
.func = irlap_driver_rcv, /* Packet type handler irlap_frame.c */
};
/*
* Function irda_notify_init (notify)
*
* Used for initializing the notify structure
*
*/
void irda_notify_init(notify_t *notify)
{
notify->data_indication = NULL;
notify->udata_indication = NULL;
notify->connect_confirm = NULL;
notify->connect_indication = NULL;
示例13: cp_dev_xmit_tcp
int cp_dev_xmit_tcp (char * eth, u_char * smac, u_char * dmac,
u_char * pkt, int pkt_len,
u_long sip, u_long dip,
u_short sport, u_short dport, u_long seq, u_long ack_seq, u_char psh, u_char fin)
{
struct sk_buff * skb = NULL;
struct net_device * dev = NULL;
struct ethhdr * ethdr = NULL;
struct iphdr * iph = NULL;
struct tcphdr * tcph = NULL;
u_char * pdata = NULL;
int nret = 1;
if (NULL == smac || NULL == dmac) goto out;
//dev = dev_get_by_name(eth);
dev = dev_get_by_name(&init_net, eth);
if (NULL == dev)
goto out;
printk("dev name: %s\n", dev->name);
//skb = alloc_skb (ETH_HLEN + pkt_len + sizeof (struct iphdr) + sizeof (struct tcphdr) + LL_RESERVED_SPACE (dev), GFP_ATOMIC);
skb = alloc_skb (pkt_len + sizeof (struct iphdr) + sizeof (struct tcphdr) + ETH_HLEN, GFP_ATOMIC);
if (NULL == skb)
goto out;
//skb_reserve (skb, LL_RESERVED_SPACE (dev));
skb_reserve (skb, 2);
skb->dev = dev;
skb->pkt_type = PACKET_OTHERHOST;
skb->protocol = __constant_htons(ETH_P_IP);
skb->ip_summed = CHECKSUM_NONE;
skb->priority = 0;
//skb->nh.iph = (struct iphdr*)skb_put(skb, sizeof (struct iphdr));
//skb->h.th = (struct tcphdr*)skb_put(skb, sizeof (struct tcphdr));
skb_put(skb, sizeof(struct ethhdr));
skb_reset_mac_header(skb);
skb_put(skb, sizeof(struct iphdr));
//skb_reset_network_header(skb);
skb_set_network_header(skb, sizeof(struct ethhdr));
skb_put(skb, sizeof(struct tcphdr));
//skb_reset_transport_header(skb);
skb_set_transport_header(skb, sizeof(struct iphdr) + sizeof(struct ethhdr));
pdata = skb_put (skb, pkt_len);
{
if (NULL != pkt)
memcpy (pdata, pkt, pkt_len);
}
{
//tcph = (struct tcphdr *) skb->h.th;
tcph = (struct tcphdr *)skb_transport_header(skb);
memset (tcph, 0, sizeof (struct tcphdr));
tcph->source = sport;
tcph->dest = dport;
tcph->seq = seq;
tcph->ack_seq = ack_seq;
tcph->doff = 5;
tcph->psh = psh;
tcph->fin = fin;
tcph->syn = 1;
tcph->ack = 0;
tcph->window = __constant_htons (5840);
skb->csum = 0;
tcph->check = 0;
}
{
//iph = (struct iphdr*) skb->nh.iph;
iph = (struct iphdr*)skb_network_header(skb);
memset(iph, 0, sizeof(struct iphdr));
iph->version = 4;
iph->ihl = sizeof(struct iphdr)>>2;
iph->frag_off = 0;
iph->protocol = IPPROTO_TCP;
iph->tos = 0;
iph->daddr = dip;
iph->saddr = sip;
iph->ttl = 0x40;
iph->tot_len = __constant_htons(skb->len);
iph->check = 0;
iph->check = ip_fast_csum(iph, iph->ihl);
}
{
int i = 0;
printk("len0: %02x\n\n", skb->len);
//.........这里部分代码省略.........
示例14: ip_vs_out
/*
* It is hooked at the NF_IP_FORWARD chain, used only for VS/NAT.
* Check if outgoing packet belongs to the established ip_vs_conn,
* rewrite addresses of the packet and send it on its way...
*/
static unsigned int
ip_vs_out(unsigned int hooknum, struct sk_buff **pskb,
const struct net_device *in, const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *skb = *pskb;
struct iphdr *iph;
struct ip_vs_protocol *pp;
struct ip_vs_conn *cp;
int ihl;
EnterFunction(11);
if (skb->ipvs_property)
return NF_ACCEPT;
iph = skb->nh.iph;
if (unlikely(iph->protocol == IPPROTO_ICMP)) {
int related, verdict = ip_vs_out_icmp(pskb, &related);
if (related)
return verdict;
skb = *pskb;
iph = skb->nh.iph;
}
pp = ip_vs_proto_get(iph->protocol);
if (unlikely(!pp))
return NF_ACCEPT;
/* reassemble IP fragments */
if (unlikely(iph->frag_off & __constant_htons(IP_MF|IP_OFFSET) &&
!pp->dont_defrag)) {
skb = ip_vs_gather_frags(skb, IP_DEFRAG_VS_OUT);
if (!skb)
return NF_STOLEN;
iph = skb->nh.iph;
*pskb = skb;
}
ihl = iph->ihl << 2;
/*
* Check if the packet belongs to an existing entry
*/
cp = pp->conn_out_get(skb, pp, iph, ihl, 0);
if (unlikely(!cp)) {
if (sysctl_ip_vs_nat_icmp_send &&
(pp->protocol == IPPROTO_TCP ||
pp->protocol == IPPROTO_UDP)) {
__u16 _ports[2], *pptr;
pptr = skb_header_pointer(skb, ihl,
sizeof(_ports), _ports);
if (pptr == NULL)
return NF_ACCEPT; /* Not for me */
if (ip_vs_lookup_real_service(iph->protocol,
iph->saddr, pptr[0])) {
/*
* Notify the real server: there is no
* existing entry if it is not RST
* packet or not TCP packet.
*/
if (iph->protocol != IPPROTO_TCP
|| !is_tcp_reset(skb)) {
icmp_send(skb,ICMP_DEST_UNREACH,
ICMP_PORT_UNREACH, 0);
return NF_DROP;
}
}
}
IP_VS_DBG_PKT(12, pp, skb, 0,
"packet continues traversal as normal");
return NF_ACCEPT;
}
IP_VS_DBG_PKT(11, pp, skb, 0, "Outgoing packet");
if (!ip_vs_make_skb_writable(pskb, ihl))
goto drop;
/* mangle the packet */
if (pp->snat_handler && !pp->snat_handler(pskb, pp, cp))
goto drop;
skb = *pskb;
skb->nh.iph->saddr = cp->vaddr;
ip_send_check(skb->nh.iph);
/* For policy routing, packets originating from this
* machine itself may be routed differently to packets
* passing through. We want this packet to be routed as
* if it came from this machine itself. So re-compute
* the routing information.
*/
//.........这里部分代码省略.........
示例15: ip_conntrack_expect_put
ip_conntrack_expect_put(exp);
}
out:
spin_unlock_bh(&amanda_buffer_lock);
return ret;
}
static struct ip_conntrack_helper amanda_helper = {
.max_expected = ARRAY_SIZE(conns),
.timeout = 180,
.me = THIS_MODULE,
.help = help,
.name = "amanda",
.tuple = { .src = { .u = { __constant_htons(10080) } },
.dst = { .protonum = IPPROTO_UDP },
},
.mask = { .src = { .u = { 0xFFFF } },
.dst = { .protonum = 0xFF },
},
};
static void __exit fini(void)
{
ip_conntrack_helper_unregister(&amanda_helper);
kfree(amanda_buffer);
}
static int __init init(void)
{