]>
Commit | Line | Data |
---|---|---|
99824461 JP |
1 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
2 | ||
1da177e4 LT |
3 | #include <linux/kernel.h> |
4 | #include <linux/string.h> | |
5a0e3ad6 | 5 | #include <linux/slab.h> |
1da177e4 LT |
6 | #include <linux/timer.h> |
7 | #include <linux/init.h> | |
8 | #include <linux/bitops.h> | |
4fc268d2 | 9 | #include <linux/capability.h> |
1da177e4 LT |
10 | #include <linux/seq_file.h> |
11 | ||
12 | /* We are an ethernet device */ | |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/netdevice.h> | |
15 | #include <linux/etherdevice.h> | |
16 | #include <net/sock.h> | |
17 | #include <linux/skbuff.h> | |
18 | #include <linux/ip.h> | |
57100440 | 19 | #include <linux/uaccess.h> |
1da177e4 | 20 | #include <asm/byteorder.h> |
1da177e4 LT |
21 | #include <net/checksum.h> /* for ip_fast_csum() */ |
22 | #include <net/arp.h> | |
23 | #include <net/dst.h> | |
24 | #include <linux/proc_fs.h> | |
25 | ||
26 | /* And atm device */ | |
27 | #include <linux/atmdev.h> | |
28 | #include <linux/atmlec.h> | |
29 | #include <linux/atmmpc.h> | |
30 | /* Modular too */ | |
1da177e4 LT |
31 | #include <linux/module.h> |
32 | ||
33 | #include "lec.h" | |
34 | #include "mpc.h" | |
35 | #include "resources.h" | |
36 | ||
37 | /* | |
f7d57453 | 38 | * mpc.c: Implementation of MPOA client kernel part |
1da177e4 LT |
39 | */ |
40 | ||
41 | #if 0 | |
b50c2ea7 JP |
42 | #define dprintk(format, args...) \ |
43 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args) | |
44 | #define dprintk_cont(format, args...) printk(KERN_CONT format, ##args) | |
1da177e4 | 45 | #else |
b50c2ea7 JP |
46 | #define dprintk(format, args...) \ |
47 | do { if (0) \ | |
48 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\ | |
49 | } while (0) | |
50 | #define dprintk_cont(format, args...) \ | |
51 | do { if (0) printk(KERN_CONT format, ##args); } while (0) | |
1da177e4 LT |
52 | #endif |
53 | ||
54 | #if 0 | |
b50c2ea7 JP |
55 | #define ddprintk(format, args...) \ |
56 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args) | |
57 | #define ddprintk_cont(format, args...) printk(KERN_CONT format, ##args) | |
1da177e4 | 58 | #else |
b50c2ea7 JP |
59 | #define ddprintk(format, args...) \ |
60 | do { if (0) \ | |
61 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\ | |
62 | } while (0) | |
63 | #define ddprintk_cont(format, args...) \ | |
64 | do { if (0) printk(KERN_CONT format, ##args); } while (0) | |
1da177e4 LT |
65 | #endif |
66 | ||
1da177e4 | 67 | /* mpc_daemon -> kernel */ |
57100440 | 68 | static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc); |
1da177e4 LT |
69 | static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc); |
70 | static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc); | |
71 | static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc); | |
72 | static void mps_death(struct k_message *msg, struct mpoa_client *mpc); | |
57100440 JP |
73 | static void clean_up(struct k_message *msg, struct mpoa_client *mpc, |
74 | int action); | |
75 | static void MPOA_cache_impos_rcvd(struct k_message *msg, | |
76 | struct mpoa_client *mpc); | |
77 | static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, | |
78 | struct mpoa_client *mpc); | |
79 | static void set_mps_mac_addr_rcvd(struct k_message *mesg, | |
80 | struct mpoa_client *mpc); | |
1da177e4 | 81 | |
cba5cbd1 DH |
82 | static const uint8_t *copy_macs(struct mpoa_client *mpc, |
83 | const uint8_t *router_mac, | |
84 | const uint8_t *tlvs, uint8_t mps_macs, | |
85 | uint8_t device_type); | |
1da177e4 LT |
86 | static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry); |
87 | ||
cba5cbd1 | 88 | static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc); |
1da177e4 LT |
89 | static void mpoad_close(struct atm_vcc *vcc); |
90 | static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb); | |
91 | ||
92 | static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb); | |
3c805a22 | 93 | static netdev_tx_t mpc_send_packet(struct sk_buff *skb, |
57100440 JP |
94 | struct net_device *dev); |
95 | static int mpoa_event_listener(struct notifier_block *mpoa_notifier, | |
96 | unsigned long event, void *dev); | |
1da177e4 | 97 | static void mpc_timer_refresh(void); |
57100440 | 98 | static void mpc_cache_check(unsigned long checking_time); |
1da177e4 LT |
99 | |
100 | static struct llc_snap_hdr llc_snap_mpoa_ctrl = { | |
101 | 0xaa, 0xaa, 0x03, | |
102 | {0x00, 0x00, 0x5e}, | |
103 | {0x00, 0x03} /* For MPOA control PDUs */ | |
f7d57453 | 104 | }; |
1da177e4 LT |
105 | static struct llc_snap_hdr llc_snap_mpoa_data = { |
106 | 0xaa, 0xaa, 0x03, | |
107 | {0x00, 0x00, 0x00}, | |
108 | {0x08, 0x00} /* This is for IP PDUs only */ | |
f7d57453 | 109 | }; |
1da177e4 LT |
110 | static struct llc_snap_hdr llc_snap_mpoa_data_tagged = { |
111 | 0xaa, 0xaa, 0x03, | |
112 | {0x00, 0x00, 0x00}, | |
113 | {0x88, 0x4c} /* This is for tagged data PDUs */ | |
f7d57453 | 114 | }; |
1da177e4 LT |
115 | |
116 | static struct notifier_block mpoa_notifier = { | |
117 | mpoa_event_listener, | |
118 | NULL, | |
119 | 0 | |
120 | }; | |
121 | ||
1da177e4 LT |
122 | struct mpoa_client *mpcs = NULL; /* FIXME */ |
123 | static struct atm_mpoa_qos *qos_head = NULL; | |
8d06afab | 124 | static DEFINE_TIMER(mpc_timer, NULL, 0, 0); |
1da177e4 LT |
125 | |
126 | ||
127 | static struct mpoa_client *find_mpc_by_itfnum(int itf) | |
128 | { | |
129 | struct mpoa_client *mpc; | |
f7d57453 | 130 | |
1da177e4 LT |
131 | mpc = mpcs; /* our global linked list */ |
132 | while (mpc != NULL) { | |
133 | if (mpc->dev_num == itf) | |
134 | return mpc; | |
f7d57453 | 135 | mpc = mpc->next; |
1da177e4 LT |
136 | } |
137 | ||
138 | return NULL; /* not found */ | |
139 | } | |
140 | ||
141 | static struct mpoa_client *find_mpc_by_vcc(struct atm_vcc *vcc) | |
142 | { | |
143 | struct mpoa_client *mpc; | |
f7d57453 | 144 | |
1da177e4 LT |
145 | mpc = mpcs; /* our global linked list */ |
146 | while (mpc != NULL) { | |
147 | if (mpc->mpoad_vcc == vcc) | |
148 | return mpc; | |
149 | mpc = mpc->next; | |
150 | } | |
151 | ||
152 | return NULL; /* not found */ | |
153 | } | |
154 | ||
155 | static struct mpoa_client *find_mpc_by_lec(struct net_device *dev) | |
156 | { | |
157 | struct mpoa_client *mpc; | |
f7d57453 | 158 | |
1da177e4 LT |
159 | mpc = mpcs; /* our global linked list */ |
160 | while (mpc != NULL) { | |
161 | if (mpc->dev == dev) | |
162 | return mpc; | |
163 | mpc = mpc->next; | |
164 | } | |
165 | ||
166 | return NULL; /* not found */ | |
167 | } | |
168 | ||
169 | /* | |
170 | * Functions for managing QoS list | |
171 | */ | |
172 | ||
173 | /* | |
174 | * Overwrites the old entry or makes a new one. | |
175 | */ | |
30d492da | 176 | struct atm_mpoa_qos *atm_mpoa_add_qos(__be32 dst_ip, struct atm_qos *qos) |
1da177e4 LT |
177 | { |
178 | struct atm_mpoa_qos *entry; | |
179 | ||
180 | entry = atm_mpoa_search_qos(dst_ip); | |
181 | if (entry != NULL) { | |
182 | entry->qos = *qos; | |
183 | return entry; | |
184 | } | |
185 | ||
186 | entry = kmalloc(sizeof(struct atm_mpoa_qos), GFP_KERNEL); | |
187 | if (entry == NULL) { | |
57100440 | 188 | pr_info("mpoa: out of memory\n"); |
1da177e4 LT |
189 | return entry; |
190 | } | |
191 | ||
192 | entry->ipaddr = dst_ip; | |
193 | entry->qos = *qos; | |
194 | ||
195 | entry->next = qos_head; | |
196 | qos_head = entry; | |
197 | ||
198 | return entry; | |
199 | } | |
200 | ||
30d492da | 201 | struct atm_mpoa_qos *atm_mpoa_search_qos(__be32 dst_ip) |
1da177e4 LT |
202 | { |
203 | struct atm_mpoa_qos *qos; | |
204 | ||
205 | qos = qos_head; | |
57100440 JP |
206 | while (qos) { |
207 | if (qos->ipaddr == dst_ip) | |
1da177e4 | 208 | break; |
1da177e4 LT |
209 | qos = qos->next; |
210 | } | |
211 | ||
212 | return qos; | |
f7d57453 | 213 | } |
1da177e4 LT |
214 | |
215 | /* | |
216 | * Returns 0 for failure | |
217 | */ | |
218 | int atm_mpoa_delete_qos(struct atm_mpoa_qos *entry) | |
219 | { | |
1da177e4 LT |
220 | struct atm_mpoa_qos *curr; |
221 | ||
57100440 JP |
222 | if (entry == NULL) |
223 | return 0; | |
1da177e4 LT |
224 | if (entry == qos_head) { |
225 | qos_head = qos_head->next; | |
226 | kfree(entry); | |
227 | return 1; | |
228 | } | |
229 | ||
230 | curr = qos_head; | |
231 | while (curr != NULL) { | |
232 | if (curr->next == entry) { | |
233 | curr->next = entry->next; | |
234 | kfree(entry); | |
235 | return 1; | |
236 | } | |
237 | curr = curr->next; | |
238 | } | |
239 | ||
240 | return 0; | |
241 | } | |
242 | ||
243 | /* this is buggered - we need locking for qos_head */ | |
244 | void atm_mpoa_disp_qos(struct seq_file *m) | |
245 | { | |
1da177e4 LT |
246 | struct atm_mpoa_qos *qos; |
247 | ||
248 | qos = qos_head; | |
249 | seq_printf(m, "QoS entries for shortcuts:\n"); | |
250 | seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n"); | |
251 | ||
1da177e4 | 252 | while (qos != NULL) { |
21454aaa | 253 | seq_printf(m, "%pI4\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n", |
57100440 JP |
254 | &qos->ipaddr, |
255 | qos->qos.txtp.max_pcr, | |
256 | qos->qos.txtp.pcr, | |
257 | qos->qos.txtp.min_pcr, | |
258 | qos->qos.txtp.max_cdv, | |
259 | qos->qos.txtp.max_sdu, | |
260 | qos->qos.rxtp.max_pcr, | |
261 | qos->qos.rxtp.pcr, | |
262 | qos->qos.rxtp.min_pcr, | |
263 | qos->qos.rxtp.max_cdv, | |
264 | qos->qos.rxtp.max_sdu); | |
1da177e4 LT |
265 | qos = qos->next; |
266 | } | |
267 | } | |
268 | ||
269 | static struct net_device *find_lec_by_itfnum(int itf) | |
270 | { | |
271 | struct net_device *dev; | |
272 | char name[IFNAMSIZ]; | |
273 | ||
274 | sprintf(name, "lec%d", itf); | |
881d966b | 275 | dev = dev_get_by_name(&init_net, name); |
f7d57453 | 276 | |
1da177e4 LT |
277 | return dev; |
278 | } | |
279 | ||
280 | static struct mpoa_client *alloc_mpc(void) | |
281 | { | |
282 | struct mpoa_client *mpc; | |
283 | ||
57100440 | 284 | mpc = kzalloc(sizeof(struct mpoa_client), GFP_KERNEL); |
1da177e4 LT |
285 | if (mpc == NULL) |
286 | return NULL; | |
1da177e4 LT |
287 | rwlock_init(&mpc->ingress_lock); |
288 | rwlock_init(&mpc->egress_lock); | |
289 | mpc->next = mpcs; | |
290 | atm_mpoa_init_cache(mpc); | |
291 | ||
292 | mpc->parameters.mpc_p1 = MPC_P1; | |
293 | mpc->parameters.mpc_p2 = MPC_P2; | |
57100440 | 294 | memset(mpc->parameters.mpc_p3, 0, sizeof(mpc->parameters.mpc_p3)); |
1da177e4 | 295 | mpc->parameters.mpc_p4 = MPC_P4; |
f7d57453 | 296 | mpc->parameters.mpc_p5 = MPC_P5; |
1da177e4 | 297 | mpc->parameters.mpc_p6 = MPC_P6; |
f7d57453 | 298 | |
1da177e4 | 299 | mpcs = mpc; |
f7d57453 | 300 | |
1da177e4 LT |
301 | return mpc; |
302 | } | |
303 | ||
304 | /* | |
305 | * | |
306 | * start_mpc() puts the MPC on line. All the packets destined | |
f7d57453 | 307 | * to the lec underneath us are now being monitored and |
1da177e4 LT |
308 | * shortcuts will be established. |
309 | * | |
310 | */ | |
311 | static void start_mpc(struct mpoa_client *mpc, struct net_device *dev) | |
312 | { | |
f7d57453 | 313 | |
b50c2ea7 | 314 | dprintk("(%s)\n", mpc->dev->name); |
788dee0a | 315 | if (!dev->netdev_ops) |
57100440 | 316 | pr_info("(%s) not starting\n", dev->name); |
788dee0a SH |
317 | else { |
318 | mpc->old_ops = dev->netdev_ops; | |
319 | mpc->new_ops = *mpc->old_ops; | |
320 | mpc->new_ops.ndo_start_xmit = mpc_send_packet; | |
321 | dev->netdev_ops = &mpc->new_ops; | |
1da177e4 | 322 | } |
1da177e4 LT |
323 | } |
324 | ||
325 | static void stop_mpc(struct mpoa_client *mpc) | |
326 | { | |
788dee0a | 327 | struct net_device *dev = mpc->dev; |
b50c2ea7 | 328 | dprintk("(%s)", mpc->dev->name); |
1da177e4 LT |
329 | |
330 | /* Lets not nullify lec device's dev->hard_start_xmit */ | |
788dee0a | 331 | if (dev->netdev_ops != &mpc->new_ops) { |
b50c2ea7 | 332 | dprintk_cont(" mpc already stopped, not fatal\n"); |
1da177e4 LT |
333 | return; |
334 | } | |
b50c2ea7 | 335 | dprintk_cont("\n"); |
f7d57453 | 336 | |
788dee0a SH |
337 | dev->netdev_ops = mpc->old_ops; |
338 | mpc->old_ops = NULL; | |
339 | ||
340 | /* close_shortcuts(mpc); ??? FIXME */ | |
1da177e4 LT |
341 | } |
342 | ||
343 | static const char *mpoa_device_type_string(char type) __attribute__ ((unused)); | |
344 | ||
345 | static const char *mpoa_device_type_string(char type) | |
346 | { | |
57100440 | 347 | switch (type) { |
1da177e4 LT |
348 | case NON_MPOA: |
349 | return "non-MPOA device"; | |
1da177e4 LT |
350 | case MPS: |
351 | return "MPS"; | |
1da177e4 LT |
352 | case MPC: |
353 | return "MPC"; | |
1da177e4 LT |
354 | case MPS_AND_MPC: |
355 | return "both MPS and MPC"; | |
1da177e4 LT |
356 | } |
357 | ||
57100440 | 358 | return "unspecified (non-MPOA) device"; |
1da177e4 LT |
359 | } |
360 | ||
361 | /* | |
b74ca3a8 WC |
362 | * lec device calls this via its netdev_priv(dev)->lane2_ops |
363 | * ->associate_indicator() when it sees a TLV in LE_ARP packet. | |
1da177e4 LT |
364 | * We fill in the pointer above when we see a LANE2 lec initializing |
365 | * See LANE2 spec 3.1.5 | |
366 | * | |
367 | * Quite a big and ugly function but when you look at it | |
368 | * all it does is to try to locate and parse MPOA Device | |
369 | * Type TLV. | |
370 | * We give our lec a pointer to this function and when the | |
371 | * lec sees a TLV it uses the pointer to call this function. | |
372 | * | |
373 | */ | |
cba5cbd1 DH |
374 | static void lane2_assoc_ind(struct net_device *dev, const u8 *mac_addr, |
375 | const u8 *tlvs, u32 sizeoftlvs) | |
1da177e4 LT |
376 | { |
377 | uint32_t type; | |
378 | uint8_t length, mpoa_device_type, number_of_mps_macs; | |
cba5cbd1 | 379 | const uint8_t *end_of_tlvs; |
1da177e4 | 380 | struct mpoa_client *mpc; |
f7d57453 | 381 | |
1da177e4 | 382 | mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */ |
b50c2ea7 | 383 | dprintk("(%s) received TLV(s), ", dev->name); |
1da177e4 LT |
384 | dprintk("total length of all TLVs %d\n", sizeoftlvs); |
385 | mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */ | |
386 | if (mpc == NULL) { | |
57100440 | 387 | pr_info("(%s) no mpc\n", dev->name); |
1da177e4 LT |
388 | return; |
389 | } | |
390 | end_of_tlvs = tlvs + sizeoftlvs; | |
391 | while (end_of_tlvs - tlvs >= 5) { | |
57100440 JP |
392 | type = ((tlvs[0] << 24) | (tlvs[1] << 16) | |
393 | (tlvs[2] << 8) | tlvs[3]); | |
1da177e4 LT |
394 | length = tlvs[4]; |
395 | tlvs += 5; | |
396 | dprintk(" type 0x%x length %02x\n", type, length); | |
397 | if (tlvs + length > end_of_tlvs) { | |
57100440 | 398 | pr_info("TLV value extends past its buffer, aborting parse\n"); |
1da177e4 LT |
399 | return; |
400 | } | |
f7d57453 | 401 | |
1da177e4 | 402 | if (type == 0) { |
57100440 JP |
403 | pr_info("mpoa: (%s) TLV type was 0, returning\n", |
404 | dev->name); | |
1da177e4 LT |
405 | return; |
406 | } | |
407 | ||
408 | if (type != TLV_MPOA_DEVICE_TYPE) { | |
409 | tlvs += length; | |
410 | continue; /* skip other TLVs */ | |
411 | } | |
412 | mpoa_device_type = *tlvs++; | |
413 | number_of_mps_macs = *tlvs++; | |
b50c2ea7 | 414 | dprintk("(%s) MPOA device type '%s', ", |
57100440 | 415 | dev->name, mpoa_device_type_string(mpoa_device_type)); |
1da177e4 LT |
416 | if (mpoa_device_type == MPS_AND_MPC && |
417 | length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */ | |
57100440 JP |
418 | pr_info("(%s) short MPOA Device Type TLV\n", |
419 | dev->name); | |
1da177e4 LT |
420 | continue; |
421 | } | |
57100440 JP |
422 | if ((mpoa_device_type == MPS || mpoa_device_type == MPC) && |
423 | length < 22 + number_of_mps_macs*ETH_ALEN) { | |
424 | pr_info("(%s) short MPOA Device Type TLV\n", dev->name); | |
1da177e4 LT |
425 | continue; |
426 | } | |
57100440 JP |
427 | if (mpoa_device_type != MPS && |
428 | mpoa_device_type != MPS_AND_MPC) { | |
b50c2ea7 | 429 | dprintk("ignoring non-MPS device "); |
57100440 JP |
430 | if (mpoa_device_type == MPC) |
431 | tlvs += 20; | |
1da177e4 LT |
432 | continue; /* we are only interested in MPSs */ |
433 | } | |
57100440 JP |
434 | if (number_of_mps_macs == 0 && |
435 | mpoa_device_type == MPS_AND_MPC) { | |
436 | pr_info("(%s) MPS_AND_MPC has zero MACs\n", dev->name); | |
1da177e4 LT |
437 | continue; /* someone should read the spec */ |
438 | } | |
b50c2ea7 JP |
439 | dprintk_cont("this MPS has %d MAC addresses\n", |
440 | number_of_mps_macs); | |
f7d57453 | 441 | |
57100440 JP |
442 | /* |
443 | * ok, now we can go and tell our daemon | |
444 | * the control address of MPS | |
445 | */ | |
1da177e4 | 446 | send_set_mps_ctrl_addr(tlvs, mpc); |
f7d57453 | 447 | |
57100440 JP |
448 | tlvs = copy_macs(mpc, mac_addr, tlvs, |
449 | number_of_mps_macs, mpoa_device_type); | |
450 | if (tlvs == NULL) | |
451 | return; | |
1da177e4 LT |
452 | } |
453 | if (end_of_tlvs - tlvs != 0) | |
57100440 JP |
454 | pr_info("(%s) ignoring %Zd bytes of trailing TLV garbage\n", |
455 | dev->name, end_of_tlvs - tlvs); | |
1da177e4 LT |
456 | } |
457 | ||
458 | /* | |
459 | * Store at least advertizing router's MAC address | |
460 | * plus the possible MAC address(es) to mpc->mps_macs. | |
461 | * For a freshly allocated MPOA client mpc->mps_macs == 0. | |
462 | */ | |
cba5cbd1 DH |
463 | static const uint8_t *copy_macs(struct mpoa_client *mpc, |
464 | const uint8_t *router_mac, | |
465 | const uint8_t *tlvs, uint8_t mps_macs, | |
466 | uint8_t device_type) | |
1da177e4 LT |
467 | { |
468 | int num_macs; | |
469 | num_macs = (mps_macs > 1) ? mps_macs : 1; | |
470 | ||
471 | if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */ | |
57100440 JP |
472 | if (mpc->number_of_mps_macs != 0) |
473 | kfree(mpc->mps_macs); | |
1da177e4 | 474 | mpc->number_of_mps_macs = 0; |
57100440 | 475 | mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL); |
1da177e4 | 476 | if (mpc->mps_macs == NULL) { |
57100440 | 477 | pr_info("(%s) out of mem\n", mpc->dev->name); |
1da177e4 LT |
478 | return NULL; |
479 | } | |
480 | } | |
481 | memcpy(mpc->mps_macs, router_mac, ETH_ALEN); | |
482 | tlvs += 20; if (device_type == MPS_AND_MPC) tlvs += 20; | |
483 | if (mps_macs > 0) | |
484 | memcpy(mpc->mps_macs, tlvs, mps_macs*ETH_ALEN); | |
485 | tlvs += mps_macs*ETH_ALEN; | |
486 | mpc->number_of_mps_macs = num_macs; | |
487 | ||
488 | return tlvs; | |
489 | } | |
490 | ||
491 | static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc) | |
492 | { | |
493 | in_cache_entry *entry; | |
494 | struct iphdr *iph; | |
495 | char *buff; | |
30d492da | 496 | __be32 ipaddr = 0; |
1da177e4 LT |
497 | |
498 | static struct { | |
499 | struct llc_snap_hdr hdr; | |
30d492da | 500 | __be32 tag; |
1da177e4 LT |
501 | } tagged_llc_snap_hdr = { |
502 | {0xaa, 0xaa, 0x03, {0x00, 0x00, 0x00}, {0x88, 0x4c}}, | |
503 | 0 | |
504 | }; | |
505 | ||
506 | buff = skb->data + mpc->dev->hard_header_len; | |
507 | iph = (struct iphdr *)buff; | |
508 | ipaddr = iph->daddr; | |
509 | ||
b50c2ea7 | 510 | ddprintk("(%s) ipaddr 0x%x\n", |
57100440 | 511 | mpc->dev->name, ipaddr); |
1da177e4 LT |
512 | |
513 | entry = mpc->in_ops->get(ipaddr, mpc); | |
514 | if (entry == NULL) { | |
515 | entry = mpc->in_ops->add_entry(ipaddr, mpc); | |
57100440 JP |
516 | if (entry != NULL) |
517 | mpc->in_ops->put(entry); | |
1da177e4 LT |
518 | return 1; |
519 | } | |
57100440 JP |
520 | /* threshold not exceeded or VCC not ready */ |
521 | if (mpc->in_ops->cache_hit(entry, mpc) != OPEN) { | |
b50c2ea7 | 522 | ddprintk("(%s) cache_hit: returns != OPEN\n", |
57100440 | 523 | mpc->dev->name); |
1da177e4 LT |
524 | mpc->in_ops->put(entry); |
525 | return 1; | |
526 | } | |
527 | ||
b50c2ea7 | 528 | ddprintk("(%s) using shortcut\n", |
57100440 | 529 | mpc->dev->name); |
1da177e4 LT |
530 | /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */ |
531 | if (iph->ttl <= 1) { | |
b50c2ea7 | 532 | ddprintk("(%s) IP ttl = %u, using LANE\n", |
57100440 | 533 | mpc->dev->name, iph->ttl); |
1da177e4 LT |
534 | mpc->in_ops->put(entry); |
535 | return 1; | |
536 | } | |
537 | iph->ttl--; | |
538 | iph->check = 0; | |
539 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); | |
540 | ||
541 | if (entry->ctrl_info.tag != 0) { | |
b50c2ea7 | 542 | ddprintk("(%s) adding tag 0x%x\n", |
57100440 | 543 | mpc->dev->name, entry->ctrl_info.tag); |
1da177e4 | 544 | tagged_llc_snap_hdr.tag = entry->ctrl_info.tag; |
57100440 JP |
545 | skb_pull(skb, ETH_HLEN); /* get rid of Eth header */ |
546 | skb_push(skb, sizeof(tagged_llc_snap_hdr)); | |
547 | /* add LLC/SNAP header */ | |
27d7ff46 ACM |
548 | skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr, |
549 | sizeof(tagged_llc_snap_hdr)); | |
1da177e4 | 550 | } else { |
57100440 JP |
551 | skb_pull(skb, ETH_HLEN); /* get rid of Eth header */ |
552 | skb_push(skb, sizeof(struct llc_snap_hdr)); | |
553 | /* add LLC/SNAP header + tag */ | |
27d7ff46 ACM |
554 | skb_copy_to_linear_data(skb, &llc_snap_mpoa_data, |
555 | sizeof(struct llc_snap_hdr)); | |
1da177e4 LT |
556 | } |
557 | ||
558 | atomic_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc); | |
559 | ATM_SKB(skb)->atm_options = entry->shortcut->atm_options; | |
560 | entry->shortcut->send(entry->shortcut, skb); | |
561 | entry->packets_fwded++; | |
562 | mpc->in_ops->put(entry); | |
563 | ||
564 | return 0; | |
565 | } | |
566 | ||
567 | /* | |
568 | * Probably needs some error checks and locking, not sure... | |
569 | */ | |
3c805a22 SH |
570 | static netdev_tx_t mpc_send_packet(struct sk_buff *skb, |
571 | struct net_device *dev) | |
1da177e4 | 572 | { |
1da177e4 LT |
573 | struct mpoa_client *mpc; |
574 | struct ethhdr *eth; | |
575 | int i = 0; | |
f7d57453 | 576 | |
1da177e4 | 577 | mpc = find_mpc_by_lec(dev); /* this should NEVER fail */ |
57100440 JP |
578 | if (mpc == NULL) { |
579 | pr_info("(%s) no MPC found\n", dev->name); | |
1da177e4 LT |
580 | goto non_ip; |
581 | } | |
582 | ||
583 | eth = (struct ethhdr *)skb->data; | |
584 | if (eth->h_proto != htons(ETH_P_IP)) | |
585 | goto non_ip; /* Multi-Protocol Over ATM :-) */ | |
586 | ||
1c9b7aa1 HX |
587 | /* Weed out funny packets (e.g., AF_PACKET or raw). */ |
588 | if (skb->len < ETH_HLEN + sizeof(struct iphdr)) | |
589 | goto non_ip; | |
590 | skb_set_network_header(skb, ETH_HLEN); | |
591 | if (skb->len < ETH_HLEN + ip_hdr(skb)->ihl * 4 || ip_hdr(skb)->ihl < 5) | |
592 | goto non_ip; | |
593 | ||
1da177e4 | 594 | while (i < mpc->number_of_mps_macs) { |
150238eb | 595 | if (ether_addr_equal(eth->h_dest, mpc->mps_macs + i * ETH_ALEN)) |
57100440 JP |
596 | if (send_via_shortcut(skb, mpc) == 0) /* try shortcut */ |
597 | return NETDEV_TX_OK; | |
1da177e4 LT |
598 | i++; |
599 | } | |
600 | ||
57100440 JP |
601 | non_ip: |
602 | return mpc->old_ops->ndo_start_xmit(skb, dev); | |
1da177e4 LT |
603 | } |
604 | ||
605 | static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg) | |
606 | { | |
607 | int bytes_left; | |
608 | struct mpoa_client *mpc; | |
609 | struct atmmpc_ioc ioc_data; | |
610 | in_cache_entry *in_entry; | |
30d492da | 611 | __be32 ipaddr; |
1da177e4 LT |
612 | |
613 | bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc)); | |
614 | if (bytes_left != 0) { | |
57100440 JP |
615 | pr_info("mpoa:Short read (missed %d bytes) from userland\n", |
616 | bytes_left); | |
1da177e4 LT |
617 | return -EFAULT; |
618 | } | |
619 | ipaddr = ioc_data.ipaddr; | |
620 | if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF) | |
621 | return -EINVAL; | |
f7d57453 | 622 | |
1da177e4 LT |
623 | mpc = find_mpc_by_itfnum(ioc_data.dev_num); |
624 | if (mpc == NULL) | |
625 | return -EINVAL; | |
f7d57453 | 626 | |
1da177e4 LT |
627 | if (ioc_data.type == MPC_SOCKET_INGRESS) { |
628 | in_entry = mpc->in_ops->get(ipaddr, mpc); | |
57100440 JP |
629 | if (in_entry == NULL || |
630 | in_entry->entry_state < INGRESS_RESOLVED) { | |
631 | pr_info("(%s) did not find RESOLVED entry from ingress cache\n", | |
1da177e4 | 632 | mpc->dev->name); |
57100440 JP |
633 | if (in_entry != NULL) |
634 | mpc->in_ops->put(in_entry); | |
1da177e4 LT |
635 | return -EINVAL; |
636 | } | |
57100440 JP |
637 | pr_info("(%s) attaching ingress SVC, entry = %pI4\n", |
638 | mpc->dev->name, &in_entry->ctrl_info.in_dst_ip); | |
1da177e4 LT |
639 | in_entry->shortcut = vcc; |
640 | mpc->in_ops->put(in_entry); | |
641 | } else { | |
57100440 | 642 | pr_info("(%s) attaching egress SVC\n", mpc->dev->name); |
1da177e4 LT |
643 | } |
644 | ||
645 | vcc->proto_data = mpc->dev; | |
646 | vcc->push = mpc_push; | |
647 | ||
648 | return 0; | |
649 | } | |
650 | ||
651 | /* | |
652 | * | |
653 | */ | |
654 | static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev) | |
655 | { | |
656 | struct mpoa_client *mpc; | |
657 | in_cache_entry *in_entry; | |
658 | eg_cache_entry *eg_entry; | |
f7d57453 | 659 | |
1da177e4 LT |
660 | mpc = find_mpc_by_lec(dev); |
661 | if (mpc == NULL) { | |
57100440 | 662 | pr_info("(%s) close for unknown MPC\n", dev->name); |
1da177e4 LT |
663 | return; |
664 | } | |
665 | ||
b50c2ea7 | 666 | dprintk("(%s)\n", dev->name); |
1da177e4 LT |
667 | in_entry = mpc->in_ops->get_by_vcc(vcc, mpc); |
668 | if (in_entry) { | |
b50c2ea7 | 669 | dprintk("(%s) ingress SVC closed ip = %pI4\n", |
57100440 | 670 | mpc->dev->name, &in_entry->ctrl_info.in_dst_ip); |
1da177e4 LT |
671 | in_entry->shortcut = NULL; |
672 | mpc->in_ops->put(in_entry); | |
673 | } | |
674 | eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc); | |
675 | if (eg_entry) { | |
b50c2ea7 | 676 | dprintk("(%s) egress SVC closed\n", mpc->dev->name); |
1da177e4 LT |
677 | eg_entry->shortcut = NULL; |
678 | mpc->eg_ops->put(eg_entry); | |
679 | } | |
680 | ||
681 | if (in_entry == NULL && eg_entry == NULL) | |
b50c2ea7 | 682 | dprintk("(%s) unused vcc closed\n", dev->name); |
1da177e4 LT |
683 | } |
684 | ||
685 | static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb) | |
686 | { | |
687 | struct net_device *dev = (struct net_device *)vcc->proto_data; | |
688 | struct sk_buff *new_skb; | |
689 | eg_cache_entry *eg; | |
690 | struct mpoa_client *mpc; | |
30d492da | 691 | __be32 tag; |
1da177e4 | 692 | char *tmp; |
f7d57453 | 693 | |
b50c2ea7 | 694 | ddprintk("(%s)\n", dev->name); |
1da177e4 | 695 | if (skb == NULL) { |
b50c2ea7 | 696 | dprintk("(%s) null skb, closing VCC\n", dev->name); |
1da177e4 LT |
697 | mpc_vcc_close(vcc, dev); |
698 | return; | |
699 | } | |
f7d57453 | 700 | |
1da177e4 | 701 | skb->dev = dev; |
57100440 JP |
702 | if (memcmp(skb->data, &llc_snap_mpoa_ctrl, |
703 | sizeof(struct llc_snap_hdr)) == 0) { | |
1da177e4 LT |
704 | struct sock *sk = sk_atm(vcc); |
705 | ||
b50c2ea7 | 706 | dprintk("(%s) control packet arrived\n", dev->name); |
1da177e4 LT |
707 | /* Pass control packets to daemon */ |
708 | skb_queue_tail(&sk->sk_receive_queue, skb); | |
709 | sk->sk_data_ready(sk, skb->len); | |
710 | return; | |
711 | } | |
712 | ||
713 | /* data coming over the shortcut */ | |
714 | atm_return(vcc, skb->truesize); | |
715 | ||
716 | mpc = find_mpc_by_lec(dev); | |
717 | if (mpc == NULL) { | |
57100440 | 718 | pr_info("(%s) unknown MPC\n", dev->name); |
1da177e4 LT |
719 | return; |
720 | } | |
721 | ||
57100440 JP |
722 | if (memcmp(skb->data, &llc_snap_mpoa_data_tagged, |
723 | sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */ | |
b50c2ea7 | 724 | ddprintk("(%s) tagged data packet arrived\n", dev->name); |
1da177e4 | 725 | |
57100440 JP |
726 | } else if (memcmp(skb->data, &llc_snap_mpoa_data, |
727 | sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */ | |
728 | pr_info("(%s) Unsupported non-tagged data packet arrived. Purging\n", | |
729 | dev->name); | |
1da177e4 LT |
730 | dev_kfree_skb_any(skb); |
731 | return; | |
732 | } else { | |
57100440 | 733 | pr_info("(%s) garbage arrived, purging\n", dev->name); |
1da177e4 LT |
734 | dev_kfree_skb_any(skb); |
735 | return; | |
736 | } | |
737 | ||
738 | tmp = skb->data + sizeof(struct llc_snap_hdr); | |
30d492da | 739 | tag = *(__be32 *)tmp; |
1da177e4 LT |
740 | |
741 | eg = mpc->eg_ops->get_by_tag(tag, mpc); | |
742 | if (eg == NULL) { | |
57100440 JP |
743 | pr_info("mpoa: (%s) Didn't find egress cache entry, tag = %u\n", |
744 | dev->name, tag); | |
1da177e4 LT |
745 | purge_egress_shortcut(vcc, NULL); |
746 | dev_kfree_skb_any(skb); | |
747 | return; | |
748 | } | |
f7d57453 | 749 | |
1da177e4 LT |
750 | /* |
751 | * See if ingress MPC is using shortcut we opened as a return channel. | |
752 | * This means we have a bi-directional vcc opened by us. | |
f7d57453 | 753 | */ |
1da177e4 LT |
754 | if (eg->shortcut == NULL) { |
755 | eg->shortcut = vcc; | |
57100440 | 756 | pr_info("(%s) egress SVC in use\n", dev->name); |
1da177e4 LT |
757 | } |
758 | ||
57100440 JP |
759 | skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag)); |
760 | /* get rid of LLC/SNAP header */ | |
761 | new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length); | |
762 | /* LLC/SNAP is shorter than MAC header :( */ | |
1da177e4 | 763 | dev_kfree_skb_any(skb); |
57100440 | 764 | if (new_skb == NULL) { |
1da177e4 LT |
765 | mpc->eg_ops->put(eg); |
766 | return; | |
767 | } | |
768 | skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */ | |
27d7ff46 ACM |
769 | skb_copy_to_linear_data(new_skb, eg->ctrl_info.DLL_header, |
770 | eg->ctrl_info.DH_length); | |
1da177e4 | 771 | new_skb->protocol = eth_type_trans(new_skb, dev); |
c1d2bbe1 | 772 | skb_reset_network_header(new_skb); |
1da177e4 | 773 | |
eddc9ec5 | 774 | eg->latest_ip_addr = ip_hdr(new_skb)->saddr; |
1da177e4 LT |
775 | eg->packets_rcvd++; |
776 | mpc->eg_ops->put(eg); | |
777 | ||
5518b29f | 778 | memset(ATM_SKB(new_skb), 0, sizeof(struct atm_skb_data)); |
1da177e4 | 779 | netif_rx(new_skb); |
1da177e4 LT |
780 | } |
781 | ||
782 | static struct atmdev_ops mpc_ops = { /* only send is required */ | |
783 | .close = mpoad_close, | |
784 | .send = msg_from_mpoad | |
785 | }; | |
786 | ||
787 | static struct atm_dev mpc_dev = { | |
788 | .ops = &mpc_ops, | |
789 | .type = "mpc", | |
790 | .number = 42, | |
4ef8d0ae | 791 | .lock = __SPIN_LOCK_UNLOCKED(mpc_dev.lock) |
1da177e4 LT |
792 | /* members not explicitly initialised will be 0 */ |
793 | }; | |
794 | ||
57100440 | 795 | static int atm_mpoa_mpoad_attach(struct atm_vcc *vcc, int arg) |
1da177e4 LT |
796 | { |
797 | struct mpoa_client *mpc; | |
798 | struct lec_priv *priv; | |
799 | int err; | |
f7d57453 | 800 | |
1da177e4 LT |
801 | if (mpcs == NULL) { |
802 | init_timer(&mpc_timer); | |
803 | mpc_timer_refresh(); | |
804 | ||
805 | /* This lets us now how our LECs are doing */ | |
806 | err = register_netdevice_notifier(&mpoa_notifier); | |
807 | if (err < 0) { | |
808 | del_timer(&mpc_timer); | |
809 | return err; | |
810 | } | |
811 | } | |
f7d57453 | 812 | |
1da177e4 LT |
813 | mpc = find_mpc_by_itfnum(arg); |
814 | if (mpc == NULL) { | |
b50c2ea7 | 815 | dprintk("allocating new mpc for itf %d\n", arg); |
1da177e4 LT |
816 | mpc = alloc_mpc(); |
817 | if (mpc == NULL) | |
818 | return -ENOMEM; | |
819 | mpc->dev_num = arg; | |
57100440 JP |
820 | mpc->dev = find_lec_by_itfnum(arg); |
821 | /* NULL if there was no lec */ | |
1da177e4 LT |
822 | } |
823 | if (mpc->mpoad_vcc) { | |
57100440 | 824 | pr_info("mpoad is already present for itf %d\n", arg); |
1da177e4 LT |
825 | return -EADDRINUSE; |
826 | } | |
827 | ||
828 | if (mpc->dev) { /* check if the lec is LANE2 capable */ | |
524ad0a7 | 829 | priv = netdev_priv(mpc->dev); |
1da177e4 LT |
830 | if (priv->lane_version < 2) { |
831 | dev_put(mpc->dev); | |
832 | mpc->dev = NULL; | |
833 | } else | |
f7d57453 | 834 | priv->lane2_ops->associate_indicator = lane2_assoc_ind; |
1da177e4 LT |
835 | } |
836 | ||
837 | mpc->mpoad_vcc = vcc; | |
838 | vcc->dev = &mpc_dev; | |
839 | vcc_insert_socket(sk_atm(vcc)); | |
57100440 JP |
840 | set_bit(ATM_VF_META, &vcc->flags); |
841 | set_bit(ATM_VF_READY, &vcc->flags); | |
1da177e4 LT |
842 | |
843 | if (mpc->dev) { | |
844 | char empty[ATM_ESA_LEN]; | |
845 | memset(empty, 0, ATM_ESA_LEN); | |
f7d57453 | 846 | |
1da177e4 LT |
847 | start_mpc(mpc, mpc->dev); |
848 | /* set address if mpcd e.g. gets killed and restarted. | |
849 | * If we do not do it now we have to wait for the next LE_ARP | |
850 | */ | |
57100440 | 851 | if (memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0) |
1da177e4 LT |
852 | send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc); |
853 | } | |
854 | ||
855 | __module_get(THIS_MODULE); | |
856 | return arg; | |
857 | } | |
858 | ||
cba5cbd1 | 859 | static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc) |
1da177e4 LT |
860 | { |
861 | struct k_message mesg; | |
862 | ||
57100440 | 863 | memcpy(mpc->mps_ctrl_addr, addr, ATM_ESA_LEN); |
f7d57453 | 864 | |
1da177e4 LT |
865 | mesg.type = SET_MPS_CTRL_ADDR; |
866 | memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN); | |
867 | msg_to_mpoad(&mesg, mpc); | |
1da177e4 LT |
868 | } |
869 | ||
870 | static void mpoad_close(struct atm_vcc *vcc) | |
871 | { | |
872 | struct mpoa_client *mpc; | |
873 | struct sk_buff *skb; | |
874 | ||
875 | mpc = find_mpc_by_vcc(vcc); | |
876 | if (mpc == NULL) { | |
57100440 | 877 | pr_info("did not find MPC\n"); |
1da177e4 LT |
878 | return; |
879 | } | |
880 | if (!mpc->mpoad_vcc) { | |
57100440 | 881 | pr_info("close for non-present mpoad\n"); |
1da177e4 LT |
882 | return; |
883 | } | |
f7d57453 | 884 | |
1da177e4 LT |
885 | mpc->mpoad_vcc = NULL; |
886 | if (mpc->dev) { | |
524ad0a7 | 887 | struct lec_priv *priv = netdev_priv(mpc->dev); |
1da177e4 LT |
888 | priv->lane2_ops->associate_indicator = NULL; |
889 | stop_mpc(mpc); | |
890 | dev_put(mpc->dev); | |
891 | } | |
892 | ||
893 | mpc->in_ops->destroy_cache(mpc); | |
894 | mpc->eg_ops->destroy_cache(mpc); | |
895 | ||
896 | while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) { | |
897 | atm_return(vcc, skb->truesize); | |
898 | kfree_skb(skb); | |
899 | } | |
f7d57453 | 900 | |
57100440 | 901 | pr_info("(%s) going down\n", |
1da177e4 LT |
902 | (mpc->dev) ? mpc->dev->name : "<unknown>"); |
903 | module_put(THIS_MODULE); | |
1da177e4 LT |
904 | } |
905 | ||
906 | /* | |
907 | * | |
908 | */ | |
909 | static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb) | |
910 | { | |
f7d57453 | 911 | |
1da177e4 | 912 | struct mpoa_client *mpc = find_mpc_by_vcc(vcc); |
57100440 | 913 | struct k_message *mesg = (struct k_message *)skb->data; |
1da177e4 | 914 | atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); |
f7d57453 | 915 | |
1da177e4 | 916 | if (mpc == NULL) { |
57100440 | 917 | pr_info("no mpc found\n"); |
1da177e4 LT |
918 | return 0; |
919 | } | |
b50c2ea7 | 920 | dprintk("(%s)", mpc->dev ? mpc->dev->name : "<unknown>"); |
57100440 | 921 | switch (mesg->type) { |
1da177e4 | 922 | case MPOA_RES_REPLY_RCVD: |
b50c2ea7 | 923 | dprintk_cont("mpoa_res_reply_rcvd\n"); |
1da177e4 LT |
924 | MPOA_res_reply_rcvd(mesg, mpc); |
925 | break; | |
926 | case MPOA_TRIGGER_RCVD: | |
b50c2ea7 | 927 | dprintk_cont("mpoa_trigger_rcvd\n"); |
1da177e4 LT |
928 | MPOA_trigger_rcvd(mesg, mpc); |
929 | break; | |
930 | case INGRESS_PURGE_RCVD: | |
b50c2ea7 | 931 | dprintk_cont("nhrp_purge_rcvd\n"); |
1da177e4 LT |
932 | ingress_purge_rcvd(mesg, mpc); |
933 | break; | |
934 | case EGRESS_PURGE_RCVD: | |
b50c2ea7 | 935 | dprintk_cont("egress_purge_reply_rcvd\n"); |
1da177e4 LT |
936 | egress_purge_rcvd(mesg, mpc); |
937 | break; | |
938 | case MPS_DEATH: | |
b50c2ea7 | 939 | dprintk_cont("mps_death\n"); |
1da177e4 LT |
940 | mps_death(mesg, mpc); |
941 | break; | |
942 | case CACHE_IMPOS_RCVD: | |
b50c2ea7 | 943 | dprintk_cont("cache_impos_rcvd\n"); |
1da177e4 LT |
944 | MPOA_cache_impos_rcvd(mesg, mpc); |
945 | break; | |
946 | case SET_MPC_CTRL_ADDR: | |
b50c2ea7 | 947 | dprintk_cont("set_mpc_ctrl_addr\n"); |
1da177e4 LT |
948 | set_mpc_ctrl_addr_rcvd(mesg, mpc); |
949 | break; | |
950 | case SET_MPS_MAC_ADDR: | |
b50c2ea7 | 951 | dprintk_cont("set_mps_mac_addr\n"); |
1da177e4 LT |
952 | set_mps_mac_addr_rcvd(mesg, mpc); |
953 | break; | |
954 | case CLEAN_UP_AND_EXIT: | |
b50c2ea7 | 955 | dprintk_cont("clean_up_and_exit\n"); |
1da177e4 LT |
956 | clean_up(mesg, mpc, DIE); |
957 | break; | |
958 | case RELOAD: | |
b50c2ea7 | 959 | dprintk_cont("reload\n"); |
1da177e4 LT |
960 | clean_up(mesg, mpc, RELOAD); |
961 | break; | |
962 | case SET_MPC_PARAMS: | |
b50c2ea7 | 963 | dprintk_cont("set_mpc_params\n"); |
1da177e4 LT |
964 | mpc->parameters = mesg->content.params; |
965 | break; | |
966 | default: | |
b50c2ea7 | 967 | dprintk_cont("unknown message %d\n", mesg->type); |
1da177e4 LT |
968 | break; |
969 | } | |
970 | kfree_skb(skb); | |
971 | ||
972 | return 0; | |
973 | } | |
974 | ||
975 | /* Remember that this function may not do things that sleep */ | |
976 | int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc) | |
977 | { | |
978 | struct sk_buff *skb; | |
979 | struct sock *sk; | |
980 | ||
981 | if (mpc == NULL || !mpc->mpoad_vcc) { | |
57100440 | 982 | pr_info("mesg %d to a non-existent mpoad\n", mesg->type); |
1da177e4 LT |
983 | return -ENXIO; |
984 | } | |
985 | ||
986 | skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC); | |
987 | if (skb == NULL) | |
988 | return -ENOMEM; | |
989 | skb_put(skb, sizeof(struct k_message)); | |
27d7ff46 | 990 | skb_copy_to_linear_data(skb, mesg, sizeof(*mesg)); |
1da177e4 | 991 | atm_force_charge(mpc->mpoad_vcc, skb->truesize); |
f7d57453 | 992 | |
1da177e4 LT |
993 | sk = sk_atm(mpc->mpoad_vcc); |
994 | skb_queue_tail(&sk->sk_receive_queue, skb); | |
995 | sk->sk_data_ready(sk, skb->len); | |
996 | ||
997 | return 0; | |
998 | } | |
999 | ||
57100440 JP |
1000 | static int mpoa_event_listener(struct notifier_block *mpoa_notifier, |
1001 | unsigned long event, void *dev_ptr) | |
1da177e4 LT |
1002 | { |
1003 | struct net_device *dev; | |
1004 | struct mpoa_client *mpc; | |
1005 | struct lec_priv *priv; | |
1006 | ||
ea110733 | 1007 | dev = dev_ptr; |
e9dc8653 | 1008 | |
721499e8 | 1009 | if (!net_eq(dev_net(dev), &init_net)) |
e9dc8653 EB |
1010 | return NOTIFY_DONE; |
1011 | ||
1da177e4 LT |
1012 | if (dev->name == NULL || strncmp(dev->name, "lec", 3)) |
1013 | return NOTIFY_DONE; /* we are only interested in lec:s */ | |
f7d57453 | 1014 | |
1da177e4 LT |
1015 | switch (event) { |
1016 | case NETDEV_REGISTER: /* a new lec device was allocated */ | |
524ad0a7 | 1017 | priv = netdev_priv(dev); |
1da177e4 LT |
1018 | if (priv->lane_version < 2) |
1019 | break; | |
1020 | priv->lane2_ops->associate_indicator = lane2_assoc_ind; | |
1021 | mpc = find_mpc_by_itfnum(priv->itfnum); | |
1022 | if (mpc == NULL) { | |
b50c2ea7 | 1023 | dprintk("allocating new mpc for %s\n", dev->name); |
1da177e4 LT |
1024 | mpc = alloc_mpc(); |
1025 | if (mpc == NULL) { | |
57100440 | 1026 | pr_info("no new mpc"); |
1da177e4 LT |
1027 | break; |
1028 | } | |
1029 | } | |
1030 | mpc->dev_num = priv->itfnum; | |
1031 | mpc->dev = dev; | |
1032 | dev_hold(dev); | |
b50c2ea7 | 1033 | dprintk("(%s) was initialized\n", dev->name); |
1da177e4 LT |
1034 | break; |
1035 | case NETDEV_UNREGISTER: | |
1036 | /* the lec device was deallocated */ | |
1037 | mpc = find_mpc_by_lec(dev); | |
1038 | if (mpc == NULL) | |
1039 | break; | |
b50c2ea7 | 1040 | dprintk("device (%s) was deallocated\n", dev->name); |
1da177e4 LT |
1041 | stop_mpc(mpc); |
1042 | dev_put(mpc->dev); | |
1043 | mpc->dev = NULL; | |
1044 | break; | |
1045 | case NETDEV_UP: | |
1046 | /* the dev was ifconfig'ed up */ | |
1047 | mpc = find_mpc_by_lec(dev); | |
1048 | if (mpc == NULL) | |
1049 | break; | |
57100440 | 1050 | if (mpc->mpoad_vcc != NULL) |
1da177e4 | 1051 | start_mpc(mpc, dev); |
1da177e4 LT |
1052 | break; |
1053 | case NETDEV_DOWN: | |
1054 | /* the dev was ifconfig'ed down */ | |
1055 | /* this means that the flow of packets from the | |
1056 | * upper layer stops | |
1057 | */ | |
1058 | mpc = find_mpc_by_lec(dev); | |
1059 | if (mpc == NULL) | |
1060 | break; | |
57100440 | 1061 | if (mpc->mpoad_vcc != NULL) |
1da177e4 | 1062 | stop_mpc(mpc); |
1da177e4 LT |
1063 | break; |
1064 | case NETDEV_REBOOT: | |
1065 | case NETDEV_CHANGE: | |
1066 | case NETDEV_CHANGEMTU: | |
1067 | case NETDEV_CHANGEADDR: | |
1068 | case NETDEV_GOING_DOWN: | |
1069 | break; | |
1070 | default: | |
1071 | break; | |
1072 | } | |
1073 | ||
1074 | return NOTIFY_DONE; | |
1075 | } | |
1076 | ||
1077 | /* | |
1078 | * Functions which are called after a message is received from mpcd. | |
1079 | * Msg is reused on purpose. | |
1080 | */ | |
1081 | ||
1082 | ||
1083 | static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc) | |
1084 | { | |
30d492da | 1085 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
1da177e4 LT |
1086 | in_cache_entry *entry; |
1087 | ||
1088 | entry = mpc->in_ops->get(dst_ip, mpc); | |
57100440 | 1089 | if (entry == NULL) { |
1da177e4 LT |
1090 | entry = mpc->in_ops->add_entry(dst_ip, mpc); |
1091 | entry->entry_state = INGRESS_RESOLVING; | |
1092 | msg->type = SND_MPOA_RES_RQST; | |
1093 | msg->content.in_info = entry->ctrl_info; | |
1094 | msg_to_mpoad(msg, mpc); | |
1095 | do_gettimeofday(&(entry->reply_wait)); | |
1096 | mpc->in_ops->put(entry); | |
1097 | return; | |
1098 | } | |
f7d57453 | 1099 | |
57100440 | 1100 | if (entry->entry_state == INGRESS_INVALID) { |
1da177e4 LT |
1101 | entry->entry_state = INGRESS_RESOLVING; |
1102 | msg->type = SND_MPOA_RES_RQST; | |
1103 | msg->content.in_info = entry->ctrl_info; | |
1104 | msg_to_mpoad(msg, mpc); | |
1105 | do_gettimeofday(&(entry->reply_wait)); | |
1106 | mpc->in_ops->put(entry); | |
1107 | return; | |
1108 | } | |
f7d57453 | 1109 | |
57100440 | 1110 | pr_info("(%s) entry already in resolving state\n", |
1da177e4 LT |
1111 | (mpc->dev) ? mpc->dev->name : "<unknown>"); |
1112 | mpc->in_ops->put(entry); | |
1da177e4 LT |
1113 | } |
1114 | ||
1115 | /* | |
1116 | * Things get complicated because we have to check if there's an egress | |
f7d57453 | 1117 | * shortcut with suitable traffic parameters we could use. |
1da177e4 | 1118 | */ |
57100440 JP |
1119 | static void check_qos_and_open_shortcut(struct k_message *msg, |
1120 | struct mpoa_client *client, | |
1121 | in_cache_entry *entry) | |
1da177e4 | 1122 | { |
30d492da | 1123 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
1da177e4 LT |
1124 | struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip); |
1125 | eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client); | |
1126 | ||
57100440 JP |
1127 | if (eg_entry && eg_entry->shortcut) { |
1128 | if (eg_entry->shortcut->qos.txtp.traffic_class & | |
1129 | msg->qos.txtp.traffic_class & | |
1130 | (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)) { | |
1131 | if (eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR) | |
1132 | entry->shortcut = eg_entry->shortcut; | |
1133 | else if (eg_entry->shortcut->qos.txtp.max_pcr > 0) | |
1134 | entry->shortcut = eg_entry->shortcut; | |
1da177e4 | 1135 | } |
57100440 | 1136 | if (entry->shortcut) { |
b50c2ea7 | 1137 | dprintk("(%s) using egress SVC to reach %pI4\n", |
21454aaa | 1138 | client->dev->name, &dst_ip); |
1da177e4 LT |
1139 | client->eg_ops->put(eg_entry); |
1140 | return; | |
1141 | } | |
1142 | } | |
1143 | if (eg_entry != NULL) | |
1144 | client->eg_ops->put(eg_entry); | |
1145 | ||
1146 | /* No luck in the egress cache we must open an ingress SVC */ | |
1147 | msg->type = OPEN_INGRESS_SVC; | |
57100440 JP |
1148 | if (qos && |
1149 | (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) { | |
1da177e4 | 1150 | msg->qos = qos->qos; |
57100440 JP |
1151 | pr_info("(%s) trying to get a CBR shortcut\n", |
1152 | client->dev->name); | |
1153 | } else | |
1154 | memset(&msg->qos, 0, sizeof(struct atm_qos)); | |
1da177e4 | 1155 | msg_to_mpoad(msg, client); |
1da177e4 LT |
1156 | } |
1157 | ||
1158 | static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc) | |
1159 | { | |
30d492da | 1160 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
1da177e4 | 1161 | in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc); |
1e4fd51e | 1162 | |
b50c2ea7 | 1163 | dprintk("(%s) ip %pI4\n", |
21454aaa | 1164 | mpc->dev->name, &dst_ip); |
b50c2ea7 | 1165 | ddprintk("(%s) entry = %p", |
57100440 JP |
1166 | mpc->dev->name, entry); |
1167 | if (entry == NULL) { | |
1168 | pr_info("(%s) ARGH, received res. reply for an entry that doesn't exist.\n", | |
1169 | mpc->dev->name); | |
1da177e4 LT |
1170 | return; |
1171 | } | |
b50c2ea7 | 1172 | ddprintk_cont(" entry_state = %d ", entry->entry_state); |
1da177e4 LT |
1173 | |
1174 | if (entry->entry_state == INGRESS_RESOLVED) { | |
57100440 | 1175 | pr_info("(%s) RESOLVED entry!\n", mpc->dev->name); |
1da177e4 LT |
1176 | mpc->in_ops->put(entry); |
1177 | return; | |
1178 | } | |
1179 | ||
1180 | entry->ctrl_info = msg->content.in_info; | |
1181 | do_gettimeofday(&(entry->tv)); | |
1182 | do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */ | |
1183 | entry->refresh_time = 0; | |
b50c2ea7 | 1184 | ddprintk_cont("entry->shortcut = %p\n", entry->shortcut); |
1da177e4 | 1185 | |
57100440 JP |
1186 | if (entry->entry_state == INGRESS_RESOLVING && |
1187 | entry->shortcut != NULL) { | |
f7d57453 | 1188 | entry->entry_state = INGRESS_RESOLVED; |
1da177e4 LT |
1189 | mpc->in_ops->put(entry); |
1190 | return; /* Shortcut already open... */ | |
1191 | } | |
1192 | ||
1193 | if (entry->shortcut != NULL) { | |
57100440 JP |
1194 | pr_info("(%s) entry->shortcut != NULL, impossible!\n", |
1195 | mpc->dev->name); | |
1da177e4 LT |
1196 | mpc->in_ops->put(entry); |
1197 | return; | |
1198 | } | |
f7d57453 | 1199 | |
1da177e4 LT |
1200 | check_qos_and_open_shortcut(msg, mpc, entry); |
1201 | entry->entry_state = INGRESS_RESOLVED; | |
1202 | mpc->in_ops->put(entry); | |
1203 | ||
1204 | return; | |
1205 | ||
1206 | } | |
1207 | ||
1208 | static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc) | |
1209 | { | |
30d492da AV |
1210 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
1211 | __be32 mask = msg->ip_mask; | |
1da177e4 LT |
1212 | in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); |
1213 | ||
57100440 JP |
1214 | if (entry == NULL) { |
1215 | pr_info("(%s) purge for a non-existing entry, ip = %pI4\n", | |
1216 | mpc->dev->name, &dst_ip); | |
1da177e4 LT |
1217 | return; |
1218 | } | |
1219 | ||
1220 | do { | |
b50c2ea7 | 1221 | dprintk("(%s) removing an ingress entry, ip = %pI4\n", |
21454aaa | 1222 | mpc->dev->name, &dst_ip); |
1da177e4 LT |
1223 | write_lock_bh(&mpc->ingress_lock); |
1224 | mpc->in_ops->remove_entry(entry, mpc); | |
1225 | write_unlock_bh(&mpc->ingress_lock); | |
1226 | mpc->in_ops->put(entry); | |
1227 | entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); | |
1228 | } while (entry != NULL); | |
f7d57453 | 1229 | } |
1da177e4 LT |
1230 | |
1231 | static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc) | |
1232 | { | |
30d492da | 1233 | __be32 cache_id = msg->content.eg_info.cache_id; |
1da177e4 | 1234 | eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc); |
f7d57453 | 1235 | |
1da177e4 | 1236 | if (entry == NULL) { |
b50c2ea7 | 1237 | dprintk("(%s) purge for a non-existing entry\n", |
57100440 | 1238 | mpc->dev->name); |
1da177e4 LT |
1239 | return; |
1240 | } | |
1241 | ||
1242 | write_lock_irq(&mpc->egress_lock); | |
1243 | mpc->eg_ops->remove_entry(entry, mpc); | |
1244 | write_unlock_irq(&mpc->egress_lock); | |
1245 | ||
1246 | mpc->eg_ops->put(entry); | |
f7d57453 | 1247 | } |
1da177e4 LT |
1248 | |
1249 | static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry) | |
1250 | { | |
1251 | struct sock *sk; | |
1252 | struct k_message *purge_msg; | |
1253 | struct sk_buff *skb; | |
1254 | ||
b50c2ea7 | 1255 | dprintk("entering\n"); |
1da177e4 | 1256 | if (vcc == NULL) { |
57100440 | 1257 | pr_info("vcc == NULL\n"); |
1da177e4 LT |
1258 | return; |
1259 | } | |
1260 | ||
1261 | skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC); | |
1262 | if (skb == NULL) { | |
57100440 | 1263 | pr_info("out of memory\n"); |
1da177e4 LT |
1264 | return; |
1265 | } | |
1266 | ||
1267 | skb_put(skb, sizeof(struct k_message)); | |
1268 | memset(skb->data, 0, sizeof(struct k_message)); | |
1269 | purge_msg = (struct k_message *)skb->data; | |
1270 | purge_msg->type = DATA_PLANE_PURGE; | |
1271 | if (entry != NULL) | |
1272 | purge_msg->content.eg_info = entry->ctrl_info; | |
1273 | ||
1274 | atm_force_charge(vcc, skb->truesize); | |
1275 | ||
1276 | sk = sk_atm(vcc); | |
1277 | skb_queue_tail(&sk->sk_receive_queue, skb); | |
1278 | sk->sk_data_ready(sk, skb->len); | |
b50c2ea7 | 1279 | dprintk("exiting\n"); |
1da177e4 LT |
1280 | } |
1281 | ||
1282 | /* | |
1283 | * Our MPS died. Tell our daemon to send NHRP data plane purge to each | |
1284 | * of the egress shortcuts we have. | |
1285 | */ | |
57100440 | 1286 | static void mps_death(struct k_message *msg, struct mpoa_client *mpc) |
1da177e4 LT |
1287 | { |
1288 | eg_cache_entry *entry; | |
1289 | ||
b50c2ea7 | 1290 | dprintk("(%s)\n", mpc->dev->name); |
1da177e4 | 1291 | |
57100440 JP |
1292 | if (memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)) { |
1293 | pr_info("(%s) wrong MPS\n", mpc->dev->name); | |
1da177e4 LT |
1294 | return; |
1295 | } | |
1296 | ||
1297 | /* FIXME: This knows too much of the cache structure */ | |
1298 | read_lock_irq(&mpc->egress_lock); | |
1299 | entry = mpc->eg_cache; | |
1300 | while (entry != NULL) { | |
1301 | purge_egress_shortcut(entry->shortcut, entry); | |
1302 | entry = entry->next; | |
1303 | } | |
1304 | read_unlock_irq(&mpc->egress_lock); | |
1305 | ||
1306 | mpc->in_ops->destroy_cache(mpc); | |
1307 | mpc->eg_ops->destroy_cache(mpc); | |
1da177e4 LT |
1308 | } |
1309 | ||
57100440 JP |
1310 | static void MPOA_cache_impos_rcvd(struct k_message *msg, |
1311 | struct mpoa_client *mpc) | |
1da177e4 LT |
1312 | { |
1313 | uint16_t holding_time; | |
1314 | eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc); | |
f7d57453 | 1315 | |
1da177e4 | 1316 | holding_time = msg->content.eg_info.holding_time; |
b50c2ea7 | 1317 | dprintk("(%s) entry = %p, holding_time = %u\n", |
57100440 JP |
1318 | mpc->dev->name, entry, holding_time); |
1319 | if (entry == NULL && holding_time) { | |
1da177e4 LT |
1320 | entry = mpc->eg_ops->add_entry(msg, mpc); |
1321 | mpc->eg_ops->put(entry); | |
1322 | return; | |
1323 | } | |
57100440 | 1324 | if (holding_time) { |
1da177e4 LT |
1325 | mpc->eg_ops->update(entry, holding_time); |
1326 | return; | |
1327 | } | |
f7d57453 | 1328 | |
1da177e4 LT |
1329 | write_lock_irq(&mpc->egress_lock); |
1330 | mpc->eg_ops->remove_entry(entry, mpc); | |
1331 | write_unlock_irq(&mpc->egress_lock); | |
1332 | ||
1333 | mpc->eg_ops->put(entry); | |
1da177e4 LT |
1334 | } |
1335 | ||
57100440 JP |
1336 | static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, |
1337 | struct mpoa_client *mpc) | |
1da177e4 LT |
1338 | { |
1339 | struct lec_priv *priv; | |
1340 | int i, retval ; | |
1341 | ||
1342 | uint8_t tlv[4 + 1 + 1 + 1 + ATM_ESA_LEN]; | |
1343 | ||
1344 | tlv[0] = 00; tlv[1] = 0xa0; tlv[2] = 0x3e; tlv[3] = 0x2a; /* type */ | |
1345 | tlv[4] = 1 + 1 + ATM_ESA_LEN; /* length */ | |
1346 | tlv[5] = 0x02; /* MPOA client */ | |
1347 | tlv[6] = 0x00; /* number of MPS MAC addresses */ | |
1348 | ||
1349 | memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */ | |
1350 | memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN); | |
1351 | ||
b50c2ea7 JP |
1352 | dprintk("(%s) setting MPC ctrl ATM address to", |
1353 | mpc->dev ? mpc->dev->name : "<unknown>"); | |
1da177e4 | 1354 | for (i = 7; i < sizeof(tlv); i++) |
b50c2ea7 JP |
1355 | dprintk_cont(" %02x", tlv[i]); |
1356 | dprintk_cont("\n"); | |
1da177e4 LT |
1357 | |
1358 | if (mpc->dev) { | |
524ad0a7 | 1359 | priv = netdev_priv(mpc->dev); |
57100440 JP |
1360 | retval = priv->lane2_ops->associate_req(mpc->dev, |
1361 | mpc->dev->dev_addr, | |
1362 | tlv, sizeof(tlv)); | |
1da177e4 | 1363 | if (retval == 0) |
57100440 JP |
1364 | pr_info("(%s) MPOA device type TLV association failed\n", |
1365 | mpc->dev->name); | |
1da177e4 LT |
1366 | retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL); |
1367 | if (retval < 0) | |
57100440 JP |
1368 | pr_info("(%s) targetless LE_ARP request failed\n", |
1369 | mpc->dev->name); | |
1da177e4 | 1370 | } |
1da177e4 LT |
1371 | } |
1372 | ||
57100440 JP |
1373 | static void set_mps_mac_addr_rcvd(struct k_message *msg, |
1374 | struct mpoa_client *client) | |
1da177e4 LT |
1375 | { |
1376 | ||
57100440 | 1377 | if (client->number_of_mps_macs) |
1da177e4 LT |
1378 | kfree(client->mps_macs); |
1379 | client->number_of_mps_macs = 0; | |
2afe37cd | 1380 | client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL); |
1da177e4 | 1381 | if (client->mps_macs == NULL) { |
57100440 | 1382 | pr_info("out of memory\n"); |
1da177e4 LT |
1383 | return; |
1384 | } | |
1385 | client->number_of_mps_macs = 1; | |
1da177e4 LT |
1386 | } |
1387 | ||
1388 | /* | |
1389 | * purge egress cache and tell daemon to 'action' (DIE, RELOAD) | |
1390 | */ | |
1391 | static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action) | |
1392 | { | |
1393 | ||
1394 | eg_cache_entry *entry; | |
1395 | msg->type = SND_EGRESS_PURGE; | |
1396 | ||
1397 | ||
1398 | /* FIXME: This knows too much of the cache structure */ | |
1399 | read_lock_irq(&mpc->egress_lock); | |
1400 | entry = mpc->eg_cache; | |
57100440 JP |
1401 | while (entry != NULL) { |
1402 | msg->content.eg_info = entry->ctrl_info; | |
b50c2ea7 | 1403 | dprintk("cache_id %u\n", entry->ctrl_info.cache_id); |
57100440 JP |
1404 | msg_to_mpoad(msg, mpc); |
1405 | entry = entry->next; | |
1da177e4 LT |
1406 | } |
1407 | read_unlock_irq(&mpc->egress_lock); | |
1408 | ||
1409 | msg->type = action; | |
1410 | msg_to_mpoad(msg, mpc); | |
1da177e4 LT |
1411 | } |
1412 | ||
1413 | static void mpc_timer_refresh(void) | |
1414 | { | |
1415 | mpc_timer.expires = jiffies + (MPC_P2 * HZ); | |
1416 | mpc_timer.data = mpc_timer.expires; | |
1417 | mpc_timer.function = mpc_cache_check; | |
1418 | add_timer(&mpc_timer); | |
1da177e4 LT |
1419 | } |
1420 | ||
57100440 | 1421 | static void mpc_cache_check(unsigned long checking_time) |
1da177e4 LT |
1422 | { |
1423 | struct mpoa_client *mpc = mpcs; | |
1424 | static unsigned long previous_resolving_check_time; | |
1425 | static unsigned long previous_refresh_time; | |
f7d57453 | 1426 | |
57100440 | 1427 | while (mpc != NULL) { |
1da177e4 LT |
1428 | mpc->in_ops->clear_count(mpc); |
1429 | mpc->eg_ops->clear_expired(mpc); | |
57100440 JP |
1430 | if (checking_time - previous_resolving_check_time > |
1431 | mpc->parameters.mpc_p4 * HZ) { | |
1da177e4 LT |
1432 | mpc->in_ops->check_resolving(mpc); |
1433 | previous_resolving_check_time = checking_time; | |
1434 | } | |
57100440 JP |
1435 | if (checking_time - previous_refresh_time > |
1436 | mpc->parameters.mpc_p5 * HZ) { | |
1da177e4 LT |
1437 | mpc->in_ops->refresh(mpc); |
1438 | previous_refresh_time = checking_time; | |
1439 | } | |
1440 | mpc = mpc->next; | |
1441 | } | |
1442 | mpc_timer_refresh(); | |
1da177e4 LT |
1443 | } |
1444 | ||
57100440 JP |
1445 | static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd, |
1446 | unsigned long arg) | |
1da177e4 LT |
1447 | { |
1448 | int err = 0; | |
1449 | struct atm_vcc *vcc = ATM_SD(sock); | |
1450 | ||
1451 | if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA) | |
1452 | return -ENOIOCTLCMD; | |
1453 | ||
1454 | if (!capable(CAP_NET_ADMIN)) | |
1455 | return -EPERM; | |
1456 | ||
1457 | switch (cmd) { | |
57100440 JP |
1458 | case ATMMPC_CTRL: |
1459 | err = atm_mpoa_mpoad_attach(vcc, (int)arg); | |
1460 | if (err >= 0) | |
1461 | sock->state = SS_CONNECTED; | |
1462 | break; | |
1463 | case ATMMPC_DATA: | |
1464 | err = atm_mpoa_vcc_attach(vcc, (void __user *)arg); | |
1465 | break; | |
1466 | default: | |
1467 | break; | |
1da177e4 LT |
1468 | } |
1469 | return err; | |
1470 | } | |
1471 | ||
1da177e4 LT |
1472 | static struct atm_ioctl atm_ioctl_ops = { |
1473 | .owner = THIS_MODULE, | |
1474 | .ioctl = atm_mpoa_ioctl, | |
1475 | }; | |
1476 | ||
1477 | static __init int atm_mpoa_init(void) | |
1478 | { | |
1479 | register_atm_ioctl(&atm_ioctl_ops); | |
1480 | ||
1da177e4 | 1481 | if (mpc_proc_init() != 0) |
99824461 | 1482 | pr_info("failed to initialize /proc/mpoa\n"); |
1da177e4 | 1483 | |
36a9f77e | 1484 | pr_info("mpc.c: initialized\n"); |
1da177e4 LT |
1485 | |
1486 | return 0; | |
1487 | } | |
1488 | ||
1489 | static void __exit atm_mpoa_cleanup(void) | |
1490 | { | |
1491 | struct mpoa_client *mpc, *tmp; | |
1492 | struct atm_mpoa_qos *qos, *nextqos; | |
1493 | struct lec_priv *priv; | |
1494 | ||
1da177e4 | 1495 | mpc_proc_clean(); |
1da177e4 LT |
1496 | |
1497 | del_timer(&mpc_timer); | |
1498 | unregister_netdevice_notifier(&mpoa_notifier); | |
1499 | deregister_atm_ioctl(&atm_ioctl_ops); | |
1500 | ||
1501 | mpc = mpcs; | |
1502 | mpcs = NULL; | |
1503 | while (mpc != NULL) { | |
1504 | tmp = mpc->next; | |
1505 | if (mpc->dev != NULL) { | |
1506 | stop_mpc(mpc); | |
524ad0a7 | 1507 | priv = netdev_priv(mpc->dev); |
1da177e4 LT |
1508 | if (priv->lane2_ops != NULL) |
1509 | priv->lane2_ops->associate_indicator = NULL; | |
1510 | } | |
b50c2ea7 | 1511 | ddprintk("about to clear caches\n"); |
1da177e4 LT |
1512 | mpc->in_ops->destroy_cache(mpc); |
1513 | mpc->eg_ops->destroy_cache(mpc); | |
b50c2ea7 | 1514 | ddprintk("caches cleared\n"); |
1da177e4 LT |
1515 | kfree(mpc->mps_macs); |
1516 | memset(mpc, 0, sizeof(struct mpoa_client)); | |
b50c2ea7 | 1517 | ddprintk("about to kfree %p\n", mpc); |
1da177e4 | 1518 | kfree(mpc); |
b50c2ea7 | 1519 | ddprintk("next mpc is at %p\n", tmp); |
1da177e4 LT |
1520 | mpc = tmp; |
1521 | } | |
1522 | ||
1523 | qos = qos_head; | |
1524 | qos_head = NULL; | |
1525 | while (qos != NULL) { | |
1526 | nextqos = qos->next; | |
b50c2ea7 | 1527 | dprintk("freeing qos entry %p\n", qos); |
1da177e4 LT |
1528 | kfree(qos); |
1529 | qos = nextqos; | |
1530 | } | |
1da177e4 LT |
1531 | } |
1532 | ||
1533 | module_init(atm_mpoa_init); | |
1534 | module_exit(atm_mpoa_cleanup); | |
1535 | ||
1536 | MODULE_LICENSE("GPL"); |