netif的linkoutput和output

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函数中被赋的值。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值