IP上层协议注册

/* This is one larger than the largest protocol value that can be
 * found in an ipv4 or ipv6 header.  Since in both cases the protocol
 * value is presented in a __u8, this is defined to be 256.
 */
#define MAX_INET_PROTOS 256


/* This is used to register protocols. */
struct net_protocol {
void (*early_demux)(struct sk_buff *skb);
int (*handler)(struct sk_buff *skb);
void (*err_handler)(struct sk_buff *skb, u32 info);
unsigned int no_policy:1,
netns_ok:1,
/* does the protocol do more stringent
* icmp tag validation than simple
* socket lookup?
*/
icmp_strict_tag_validation:1;

};

const struct net_protocol  *inet_protos[MAX_INET_PROTOS];

int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol)
{
if (!prot->netns_ok) {
pr_err("Protocol %u is not namespace aware, cannot register.\n",
protocol);
return -EINVAL;
}


return !cmpxchg((const struct net_protocol **)&inet_protos[protocol],
NULL, prot) ? 0 : -1;
}
EXPORT_SYMBOL(inet_add_protocol);


int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol)
{
int ret;


ret = (cmpxchg((const struct net_protocol **)&inet_protos[protocol],
      prot, NULL) == prot) ? 0 : -1;


synchronize_net();


return ret;
}
EXPORT_SYMBOL(inet_del_protocol);


inet_add_protocol(&icmp_protocol, IPPROTO_ICMP)

inet_add_protocol(&udp_protocol, IPPROTO_UDP)

inet_add_protocol(&tcp_protocol, IPPROTO_TCP)

inet_add_protocol(&igmp_protocol, IPPROTO_IGMP)

inet_add_protocol(&net_gre_protocol, IPPROTO_GRE)

inet_add_protocol(&pim_protocol, IPPROTO_PIM)

inet_add_protocol(&dccp_v4_protocol, IPPROTO_DCCP)

inet_add_protocol(&l2tp_ip_protocol, IPPROTO_L2TP)

inet_add_protocol(&sctp_protocol, IPPROTO_SCTP)

inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)

inet_add_protocol(&tunnel64_protocol, IPPROTO_IPV6)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值