📄 ipsec_tunnel.c
字号:
saddr, daddr, len, type, dev->name, prv->dev->name, da[0], da[1], da[2], da[3], da[4], da[5]);#ifdef NET_21 KLIPS_PRINTMORE(debug_tunnel & DB_TN_REVEC, "ip=%08x->%08x\n", (__u32)ntohl(skb->nh.iph->saddr), (__u32)ntohl(skb->nh.iph->daddr) );#else /* NET_21 */ KLIPS_PRINTMORE(debug_tunnel & DB_TN_REVEC, "ip=%08x->%08x\n", (__u32)ntohl(skb->ip_hdr->saddr), (__u32)ntohl(skb->ip_hdr->daddr) );#endif /* NET_21 */ } else { KLIPS_PRINT(debug_tunnel, "klips_debug:ipsec_tunnel_hard_header: " "is IPv6 packet, skip debugging messages, only revector and build linklocal header.\n"); } tmp = skb->dev; skb->dev = prv->dev; ret = prv->hard_header(skb, prv->dev, type, (void *)daddr, (void *)saddr, len); skb->dev = tmp; return ret;}DEBUG_NO_STATIC int#ifdef NET_21ipsec_tunnel_rebuild_header(struct sk_buff *skb)#else /* NET_21 */ipsec_tunnel_rebuild_header(void *buff, struct net_device *dev, unsigned long raddr, struct sk_buff *skb)#endif /* NET_21 */{ struct ipsecpriv *prv = skb->dev->priv; struct net_device *tmp; int ret; struct net_device_stats *stats; /* This device's statistics */ if(skb->dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_rebuild_header: " "no device..."); return -ENODEV; } if(prv == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_rebuild_header: " "no private space associated with dev=%s", skb->dev->name ? skb->dev->name : "NULL"); return -ENODEV; } stats = (struct net_device_stats *) &(prv->mystats); if(prv->dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_rebuild_header: " "no physical device associated with dev=%s", skb->dev->name ? skb->dev->name : "NULL"); stats->tx_dropped++; return -ENODEV; } if(!prv->rebuild_header) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_rebuild_header: " "physical device has been detached, packet dropped skb->dev=%s->NULL ", skb->dev->name);#ifdef NET_21 KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "ip=%08x->%08x\n", (__u32)ntohl(skb->nh.iph->saddr), (__u32)ntohl(skb->nh.iph->daddr) );#else /* NET_21 */ KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "ip=%08x->%08x\n", (__u32)ntohl(skb->ip_hdr->saddr), (__u32)ntohl(skb->ip_hdr->daddr) );#endif /* NET_21 */ stats->tx_dropped++; return -ENODEV; } KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel: " "Revectored rebuild_header dev=%s->%s ", skb->dev->name, prv->dev->name);#ifdef NET_21 KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "ip=%08x->%08x\n", (__u32)ntohl(skb->nh.iph->saddr), (__u32)ntohl(skb->nh.iph->daddr) );#else /* NET_21 */ KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "ip=%08x->%08x\n", (__u32)ntohl(skb->ip_hdr->saddr), (__u32)ntohl(skb->ip_hdr->daddr) );#endif /* NET_21 */ tmp = skb->dev; skb->dev = prv->dev; #ifdef NET_21 ret = prv->rebuild_header(skb);#else /* NET_21 */ ret = prv->rebuild_header(buff, prv->dev, raddr, skb);#endif /* NET_21 */ skb->dev = tmp; return ret;}DEBUG_NO_STATIC intipsec_tunnel_set_mac_address(struct net_device *dev, void *addr){ struct ipsecpriv *prv = dev->priv; struct net_device_stats *stats; /* This device's statistics */ if(dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_set_mac_address: " "no device..."); return -ENODEV; } if(prv == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_set_mac_address: " "no private space associated with dev=%s", dev->name ? dev->name : "NULL"); return -ENODEV; } stats = (struct net_device_stats *) &(prv->mystats); if(prv->dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_set_mac_address: " "no physical device associated with dev=%s", dev->name ? dev->name : "NULL"); stats->tx_dropped++; return -ENODEV; } if(!prv->set_mac_address) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_set_mac_address: " "physical device has been detached, cannot set - skb->dev=%s->NULL\n", dev->name); return -ENODEV; } KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_set_mac_address: " "Revectored dev=%s->%s addr=0p%p\n", dev->name, prv->dev->name, addr); return prv->set_mac_address(prv->dev, addr);}#ifndef NET_21DEBUG_NO_STATIC voidipsec_tunnel_cache_bind(struct hh_cache **hhp, struct net_device *dev, unsigned short htype, __u32 daddr){ struct ipsecpriv *prv = dev->priv; struct net_device_stats *stats; /* This device's statistics */ if(dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_bind: " "no device..."); return; } if(prv == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_bind: " "no private space associated with dev=%s", dev->name ? dev->name : "NULL"); return; } stats = (struct net_device_stats *) &(prv->mystats); if(prv->dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_bind: " "no physical device associated with dev=%s", dev->name ? dev->name : "NULL"); stats->tx_dropped++; return; } if(!prv->header_cache_bind) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_bind: " "physical device has been detached, cannot set - skb->dev=%s->NULL\n", dev->name); stats->tx_dropped++; return; } KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_bind: " "Revectored \n"); prv->header_cache_bind(hhp, prv->dev, htype, daddr); return;}#endif /* !NET_21 */DEBUG_NO_STATIC voidipsec_tunnel_cache_update(struct hh_cache *hh, struct net_device *dev, unsigned char * haddr){ struct ipsecpriv *prv = dev->priv; struct net_device_stats *stats; /* This device's statistics */ if(dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_update: " "no device..."); return; } if(prv == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_update: " "no private space associated with dev=%s", dev->name ? dev->name : "NULL"); return; } stats = (struct net_device_stats *) &(prv->mystats); if(prv->dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_update: " "no physical device associated with dev=%s", dev->name ? dev->name : "NULL"); stats->tx_dropped++; return; } if(!prv->header_cache_update) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_cache_update: " "physical device has been detached, cannot set - skb->dev=%s->NULL\n", dev->name); return; } KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel: " "Revectored cache_update\n"); prv->header_cache_update(hh, prv->dev, haddr); return;}#ifdef NET_21DEBUG_NO_STATIC intipsec_tunnel_neigh_setup(struct neighbour *n){ KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_neigh_setup:\n"); if (n->nud_state == NUD_NONE) { n->ops = &arp_broken_ops; n->output = n->ops->output; } return 0;}DEBUG_NO_STATIC intipsec_tunnel_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p){ KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_neigh_setup_dev: " "setting up %s\n", dev ? dev->name : "NULL"); if (p->tbl->family == AF_INET) { p->neigh_setup = ipsec_tunnel_neigh_setup; p->ucast_probes = 0; p->mcast_probes = 0; } return 0;}#endif /* NET_21 *//* * We call the attach routine to attach another device. */DEBUG_NO_STATIC intipsec_tunnel_attach(struct net_device *dev, struct net_device *physdev){ int i; struct ipsecpriv *prv = dev->priv; if(dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_attach: " "no device..."); return -ENODEV; } if(prv == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_attach: " "no private space associated with dev=%s", dev->name ? dev->name : "NULL"); return -ENODATA; } prv->dev = physdev; prv->hard_start_xmit = physdev->hard_start_xmit; prv->get_stats = physdev->get_stats; if (physdev->hard_header) { prv->hard_header = physdev->hard_header; dev->hard_header = ipsec_tunnel_hard_header; } else dev->hard_header = NULL; if (physdev->rebuild_header) { prv->rebuild_header = physdev->rebuild_header; dev->rebuild_header = ipsec_tunnel_rebuild_header; } else dev->rebuild_header = NULL; if (physdev->set_mac_address) { prv->set_mac_address = physdev->set_mac_address; dev->set_mac_address = ipsec_tunnel_set_mac_address; } else dev->set_mac_address = NULL; #ifndef NET_21 if (physdev->header_cache_bind) { prv->header_cache_bind = physdev->header_cache_bind; dev->header_cache_bind = ipsec_tunnel_cache_bind; } else dev->header_cache_bind = NULL;#endif /* !NET_21 */ if (physdev->header_cache_update) { prv->header_cache_update = physdev->header_cache_update; dev->header_cache_update = ipsec_tunnel_cache_update; } else dev->header_cache_update = NULL; dev->hard_header_len = physdev->hard_header_len;#ifdef NET_21/* prv->neigh_setup = physdev->neigh_setup; */ dev->neigh_setup = ipsec_tunnel_neigh_setup_dev;#endif /* NET_21 */ dev->mtu = 16260; /* 0xfff0; */ /* dev->mtu; */ prv->mtu = physdev->mtu;#ifdef PHYSDEV_TYPE dev->type = physdev->type; /* ARPHRD_TUNNEL; */#endif /* PHYSDEV_TYPE */ dev->addr_len = physdev->addr_len; for (i=0; i<dev->addr_len; i++) { dev->dev_addr[i] = physdev->dev_addr[i]; }#ifdef CONFIG_KLIPS_DEBUG if(debug_tunnel & DB_TN_INIT) { printk(KERN_INFO "klips_debug:ipsec_tunnel_attach: " "physical device %s being attached has HW address: %2x", physdev->name, physdev->dev_addr[0]); for (i=1; i < physdev->addr_len; i++) { printk(":%02x", physdev->dev_addr[i]); } printk("\n"); }#endif /* CONFIG_KLIPS_DEBUG */ return 0;}/* * We call the detach routine to detach the ipsec tunnel from another device. */DEBUG_NO_STATIC intipsec_tunnel_detach(struct net_device *dev){ int i; struct ipsecpriv *prv = dev->priv; if(dev == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_detach: " "no device..."); return -ENODEV; } if(prv == NULL) { KLIPS_PRINT(debug_tunnel & DB_TN_REVEC, "klips_debug:ipsec_tunnel_detach: " "no private space associated with dev=%s", dev->name ? dev->name : "NULL"); return -ENODATA; } KLIPS_PRINT(debug_tunnel & DB_TN_INIT, "klips_debug:ipsec_tunnel_detach: " "physical device %s being detached from virtual device %s\n", prv->dev ? prv->dev->name : "NULL", dev->name); ipsec_dev_put(prv->dev); prv->dev = NULL; prv->hard_start_xmit = NULL; prv->get_stats = NULL; prv->hard_header = NULL;#ifdef DETACH_AND_DOWN dev->hard_header = NULL;#endif /* DETACH_AND_DOWN */ prv->rebuild_header = NULL;#ifdef DETACH_AND_DOWN dev->rebuild_header = NULL;#endif /* DETACH_AND_DOWN */ prv->set_mac_address = NULL;#ifdef DETACH_AND_DOWN dev->set_mac_address = NULL;#endif /* DETACH_AND_DOWN */ #ifndef NET_21 prv->header_cache_bind = NULL;#ifdef DETACH_AND_DOWN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -