Change NHLFE MTU calculation
[mpls-linux.git] / src / mplsbr.c
blob46c0641365476988a68fccd373e7cfc62934bc13
1 /* mplsbr.c: ethernet over MPLS protocol driver.
3 * Copyright (C) 2005 James R. Leu (jleu@mindspring.com)
4 */
6 #include <linux/module.h>
7 #include <linux/socket.h>
8 #include <linux/skbuff.h>
9 #include <linux/init.h>
10 #include <net/neighbour.h>
11 #include <net/dst.h>
12 #include <net/mpls.h>
14 MODULE_LICENSE("GPL");
16 static void dumb_neigh_solicit(struct neighbour *neigh,struct sk_buff *skb)
20 static void dumb_neigh_error(struct neighbour *neigh,struct sk_buff *skb)
22 kfree_skb(skb);
25 static int dumb_neigh_dev_xmit(struct sk_buff *skb)
27 skb->dev = skb_dst(skb)->dev;
28 skb->ip_summed = CHECKSUM_NONE;
29 dev_queue_xmit(skb);
30 return 0;
34 static struct neigh_ops dumb_neigh_ops = {
35 .family = AF_PACKET,
36 .solicit = dumb_neigh_solicit,
37 .error_report = dumb_neigh_error,
38 .output = dumb_neigh_dev_xmit,
39 .connected_output = dumb_neigh_dev_xmit,
40 .hh_output = dumb_neigh_dev_xmit,
41 .queue_xmit = dumb_neigh_dev_xmit,
44 static u32 dumb_neigh_hash(const void *pkey, const struct net_device *dev)
46 return dev->ifindex;
49 static int dumb_neigh_constructor(struct neighbour *neigh)
51 neigh->ops = &dumb_neigh_ops;
52 neigh->output = neigh->ops->output;
53 return 0;
56 static struct neigh_table dumb_tbl = {
57 .family = AF_PACKET,
58 .entry_size = sizeof(struct neighbour),
59 .key_len = 4,
60 .hash = dumb_neigh_hash,
61 .constructor = dumb_neigh_constructor,
62 .id = "dumb_neigh",
64 /* parameters are copied from ARP ... */
65 .parms = {
66 .tbl = &dumb_tbl,
67 .base_reachable_time = 30 * HZ,
68 .retrans_time = 1 * HZ,
69 .gc_staletime = 60 * HZ,
70 .reachable_time = 30 * HZ,
71 .delay_probe_time = 5 * HZ,
72 .queue_len = 3,
73 .ucast_probes = 3,
74 .mcast_probes = 3,
75 .anycast_delay = 1 * HZ,
76 .proxy_delay = (8 * HZ) / 10,
77 .proxy_qlen = 64,
78 .locktime = 1 * HZ,
80 .gc_interval = 30 * HZ,
81 .gc_thresh1 = 128,
82 .gc_thresh2 = 512,
83 .gc_thresh3 = 1024,
86 static void mplsbr_cache_flush(struct net *net)
90 static void mplsbr_set_ttl(struct sk_buff *skb, int ttl)
94 static int mplsbr_get_ttl(struct sk_buff *skb)
96 return 255;
99 static void mplsbr_change_dsfield(struct sk_buff *skb, int ds)
101 /* 802.1q? */
104 static int mplsbr_get_dsfield(struct sk_buff *skb)
106 /* 802.1q? */
107 return 0;
110 static int mplsbr_ttl_expired(struct sk_buff **skb)
112 return NET_RX_DROP;
115 static int mplsbr_mtu_exceeded(struct sk_buff **skb, int mtu)
117 return MPLS_RESULT_DROP;
120 static int mplsbr_local_deliver(struct sk_buff *skb)
122 return NET_RX_DROP;
125 static int mplsbr_nexthop_resolve(struct neighbour **np,
126 struct sockaddr *sock_addr, struct net_device *dev)
128 struct neighbour *n;
129 u32 index = dev->ifindex;
131 n = __neigh_lookup_errno(&dumb_tbl, &index, dev);
132 if (IS_ERR(n))
133 return PTR_ERR(n);
135 *np = n;
136 return 0;
139 static struct mpls_prot_driver mplsbr_driver = {
140 .name = "bridge",
141 .family = AF_PACKET,
142 .ethertype = __constant_htons(ETH_P_ALL),
143 .cache_flush = mplsbr_cache_flush,
144 .set_ttl = mplsbr_set_ttl,
145 .get_ttl = mplsbr_get_ttl,
146 .change_dsfield = mplsbr_change_dsfield,
147 .get_dsfield = mplsbr_get_dsfield,
148 .ttl_expired = mplsbr_ttl_expired,
149 .mtu_exceeded = mplsbr_mtu_exceeded,
150 .local_deliver = mplsbr_local_deliver,
151 .nexthop_resolve = mplsbr_nexthop_resolve,
152 .owner = THIS_MODULE,
155 static int __init mplsbr_init(void)
157 printk("MPLS: Ethernet over MPLS support\n");
158 neigh_table_init(&dumb_tbl);
159 return mpls_proto_add(&mplsbr_driver);
162 static void __exit mplsbr_fini(void)
164 mpls_proto_remove(&mplsbr_driver);
167 module_init(mplsbr_init);
168 module_exit(mplsbr_fini);