/* * Transmit a packet (called by the kernel) */ int snull_tx(struct sk_buff *skb, struct net_device *dev) { int len, retval=0; char *data; struct snull_priv *priv = (struct snull_priv *)dev->priv; #ifndef LINUX_24 if (dev->tbusy || skb == NULL) { PDEBUG("tint for %p, tbusy %ld, skb %p\n", dev, dev->tbusy, skb); snull_tx_timeout (dev); if (skb == NULL) return 0; } #endif len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len; data = skb->data; dev->trans_start = jiffies; /* save the timestamp */ /* Remember the skb, so we can free it at interrupt time */ priv->skb = skb; /* actual deliver of data is device-specific, and not shown here */ snull_hw_tx(data, len, dev); return retval; /* zero == done; nonzero == fail */ }
/* * 当内核有需要发送的数据包时候调用此发包函数(used by kernel) */ int snull_tx(struct sk_buff *skb, struct net_device *dev) { printk("snull_tx\n"); int len; char *data; struct snull_priv *priv = netdev_priv(dev); len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;//ETH_ZLEN是所发的最小数据包的长度 data = skb->data;//将要发送的数据包中数据部分 dev->trans_start = jiffies;//保存当前的发送时间 priv->skb = skb; snull_hw_tx(data, len, dev);//真正的发送函数 return NETDEV_TX_OK; }