LwIP的注释说的很清楚:
/** This function is called by the network device driver
* to pass a packet up the TCP/IP stack. */
netif_input_fn input;
/** This function is called by the IP module when it wants
* to send a packet on the interface. This function typically
* first resolves the hardware address, then sends the packet. */
netif_output_fn output;
/** This function is called by the ARP module when it wants
* to send a packet on the interface. This function outputs
* the pbuf as-is on the link medium. */
netif_linkoutput_fn linkoutput;
对于以太网接口的网卡来说:
linkoutput实际指向low_level_output,由ARP层调用,参数是:netif,ETH包
output实际指向etharp_output,由IP层调用,参数是:netif,IP包,目的IP地址
它们功能上的区别是:linkoutput是发送ETH包,output是发送IP包。
linkoutput是在已知目的MAC地址时调用,而output则相反。
output底层也是调用了linkoutput来发送组装好的ETH包的
对于SLIP(Serial Line Internet Protocol,串行线路网际协议)的网卡,它的output是slipif_output。
对于PPPoE(Point to Point Protocol over Ethernet)的网卡,它的output是pppifOutput。
这两种网络接口都用不到IP地址,不需要ARP,不需要linkoutput,直接在output内发送数据包
/**
* Add a network interface to the list of lwIP netifs.
*
* @param netif a pre-allocated netif structure
* @param ipaddr IP address for the new netif
* @param netmask network mask for the new netif
* @param gw default gateway IP address for the new netif
* @param state opaque data passed to the new netif
* @param init callback function that initializes the interface
* @param input callback function that is called to pass
* ingress packets up in the protocol layer stack.
*
* @return netif, or NULL if failed.
*/
struct netif *
netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
netif_add函数有input,但是没有output和linkoutput,为什么呢?
因为linkoutput不是必须的,像SLIP和PPPoE就没有,所以它们是在init函数中被赋的值。