Blame view

net/atm/mpc.c 38.9 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
  #include <linux/kernel.h>
  #include <linux/string.h>
  #include <linux/timer.h>
  #include <linux/init.h>
  #include <linux/bitops.h>
4fc268d24   Randy Dunlap   [PATCH] capable/c...
6
  #include <linux/capability.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <linux/seq_file.h>
  
  /* We are an ethernet device */
  #include <linux/if_ether.h>
  #include <linux/netdevice.h>
  #include <linux/etherdevice.h>
  #include <net/sock.h>
  #include <linux/skbuff.h>
  #include <linux/ip.h>
  #include <asm/byteorder.h>
  #include <asm/uaccess.h>
  #include <net/checksum.h>   /* for ip_fast_csum() */
  #include <net/arp.h>
  #include <net/dst.h>
  #include <linux/proc_fs.h>
  
  /* And atm device */
  #include <linux/atmdev.h>
  #include <linux/atmlec.h>
  #include <linux/atmmpc.h>
  /* Modular too */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
30
31
32
33
34
  #include <linux/module.h>
  
  #include "lec.h"
  #include "mpc.h"
  #include "resources.h"
  
  /*
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
35
   * mpc.c: Implementation of MPOA client kernel part
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
   */
  
  #if 0
  #define dprintk printk   /* debug */
  #else
  #define dprintk(format,args...)
  #endif
  
  #if 0
  #define ddprintk printk  /* more debug */
  #else
  #define ddprintk(format,args...)
  #endif
  
  
  
  #define MPOA_TAG_LEN 4
  
  /* mpc_daemon -> kernel */
  static void MPOA_trigger_rcvd (struct k_message *msg, struct mpoa_client *mpc);
  static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  static void mps_death(struct k_message *msg, struct mpoa_client *mpc);
  static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action);
  static void MPOA_cache_impos_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, struct mpoa_client *mpc);
  static void set_mps_mac_addr_rcvd(struct k_message *mesg, struct mpoa_client *mpc);
  
  static uint8_t *copy_macs(struct mpoa_client *mpc, uint8_t *router_mac,
  			  uint8_t *tlvs, uint8_t mps_macs, uint8_t device_type);
  static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry);
  
  static void send_set_mps_ctrl_addr(char *addr, struct mpoa_client *mpc);
  static void mpoad_close(struct atm_vcc *vcc);
  static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb);
  
  static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb);
  static int mpc_send_packet(struct sk_buff *skb, struct net_device *dev);
  static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned long event, void *dev);
  static void mpc_timer_refresh(void);
  static void mpc_cache_check( unsigned long checking_time  );
  
  static struct llc_snap_hdr llc_snap_mpoa_ctrl = {
  	0xaa, 0xaa, 0x03,
  	{0x00, 0x00, 0x5e},
  	{0x00, 0x03}         /* For MPOA control PDUs */
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
83
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
85
86
87
  static struct llc_snap_hdr llc_snap_mpoa_data = {
  	0xaa, 0xaa, 0x03,
  	{0x00, 0x00, 0x00},
  	{0x08, 0x00}         /* This is for IP PDUs only */
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
88
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
90
91
92
  static struct llc_snap_hdr llc_snap_mpoa_data_tagged = {
  	0xaa, 0xaa, 0x03,
  	{0x00, 0x00, 0x00},
  	{0x88, 0x4c}         /* This is for tagged data PDUs */
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
93
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
95
96
97
98
99
  
  static struct notifier_block mpoa_notifier = {
  	mpoa_event_listener,
  	NULL,
  	0
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
  struct mpoa_client *mpcs = NULL; /* FIXME */
  static struct atm_mpoa_qos *qos_head = NULL;
8d06afab7   Ingo Molnar   [PATCH] timer ini...
102
  static DEFINE_TIMER(mpc_timer, NULL, 0, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
107
  
  
  static struct mpoa_client *find_mpc_by_itfnum(int itf)
  {
  	struct mpoa_client *mpc;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
108

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
112
  	mpc = mpcs;  /* our global linked list */
  	while (mpc != NULL) {
  		if (mpc->dev_num == itf)
  			return mpc;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
113
  		mpc = mpc->next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
115
116
117
118
119
120
121
  	}
  
  	return NULL;   /* not found */
  }
  
  static struct mpoa_client *find_mpc_by_vcc(struct atm_vcc *vcc)
  {
  	struct mpoa_client *mpc;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
122

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
124
125
126
127
128
129
130
131
132
133
134
135
  	mpc = mpcs;  /* our global linked list */
  	while (mpc != NULL) {
  		if (mpc->mpoad_vcc == vcc)
  			return mpc;
  		mpc = mpc->next;
  	}
  
  	return NULL;   /* not found */
  }
  
  static struct mpoa_client *find_mpc_by_lec(struct net_device *dev)
  {
  	struct mpoa_client *mpc;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
136

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  	mpc = mpcs;  /* our global linked list */
  	while (mpc != NULL) {
  		if (mpc->dev == dev)
  			return mpc;
  		mpc = mpc->next;
  	}
  
  	return NULL;   /* not found */
  }
  
  /*
   * Functions for managing QoS list
   */
  
  /*
   * Overwrites the old entry or makes a new one.
   */
30d492da7   Al Viro   [ATM]: Annotations.
154
  struct atm_mpoa_qos *atm_mpoa_add_qos(__be32 dst_ip, struct atm_qos *qos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  {
  	struct atm_mpoa_qos *entry;
  
  	entry = atm_mpoa_search_qos(dst_ip);
  	if (entry != NULL) {
  		entry->qos = *qos;
  		return entry;
  	}
  
  	entry = kmalloc(sizeof(struct atm_mpoa_qos), GFP_KERNEL);
  	if (entry == NULL) {
  		printk("mpoa: atm_mpoa_add_qos: out of memory
  ");
  		return entry;
  	}
  
  	entry->ipaddr = dst_ip;
  	entry->qos = *qos;
  
  	entry->next = qos_head;
  	qos_head = entry;
  
  	return entry;
  }
30d492da7   Al Viro   [ATM]: Annotations.
179
  struct atm_mpoa_qos *atm_mpoa_search_qos(__be32 dst_ip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
181
182
183
184
185
186
187
188
189
190
191
  {
  	struct atm_mpoa_qos *qos;
  
  	qos = qos_head;
  	while( qos != NULL ){
  		if(qos->ipaddr == dst_ip) {
  			break;
  		}
  		qos = qos->next;
  	}
  
  	return qos;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
192
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
  
  /*
   * Returns 0 for failure
   */
  int atm_mpoa_delete_qos(struct atm_mpoa_qos *entry)
  {
  
  	struct atm_mpoa_qos *curr;
  
  	if (entry == NULL) return 0;
  	if (entry == qos_head) {
  		qos_head = qos_head->next;
  		kfree(entry);
  		return 1;
  	}
  
  	curr = qos_head;
  	while (curr != NULL) {
  		if (curr->next == entry) {
  			curr->next = entry->next;
  			kfree(entry);
  			return 1;
  		}
  		curr = curr->next;
  	}
  
  	return 0;
  }
  
  /* this is buggered - we need locking for qos_head */
  void atm_mpoa_disp_qos(struct seq_file *m)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
226
227
228
229
230
231
232
233
  	struct atm_mpoa_qos *qos;
  
  	qos = qos_head;
  	seq_printf(m, "QoS entries for shortcuts:
  ");
  	seq_printf(m, "IP address
    TX:max_pcr pcr     min_pcr max_cdv max_sdu
    RX:max_pcr pcr     min_pcr max_cdv max_sdu
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
  	while (qos != NULL) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
236
237
238
  		seq_printf(m, "%u.%u.%u.%u
       %-7d %-7d %-7d %-7d %-7d
       %-7d %-7d %-7d %-7d %-7d
  ",
ff7512e1a   Al Viro   [ATM]: fix broken...
239
  				NIPQUAD(qos->ipaddr),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
240
241
242
243
244
245
246
247
248
249
250
251
252
  				qos->qos.txtp.max_pcr, qos->qos.txtp.pcr, qos->qos.txtp.min_pcr, qos->qos.txtp.max_cdv, qos->qos.txtp.max_sdu,
  				qos->qos.rxtp.max_pcr, qos->qos.rxtp.pcr, qos->qos.rxtp.min_pcr, qos->qos.rxtp.max_cdv, qos->qos.rxtp.max_sdu);
  		qos = qos->next;
  	}
  }
  
  static struct net_device *find_lec_by_itfnum(int itf)
  {
  	struct net_device *dev;
  	char name[IFNAMSIZ];
  
  	sprintf(name, "lec%d", itf);
  	dev = dev_get_by_name(name);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
253

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
254
255
256
257
258
259
  	return dev;
  }
  
  static struct mpoa_client *alloc_mpc(void)
  {
  	struct mpoa_client *mpc;
0da974f4f   Panagiotis Issaris   [NET]: Conversion...
260
  	mpc = kzalloc(sizeof (struct mpoa_client), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
262
  	if (mpc == NULL)
  		return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263
264
265
266
267
268
269
270
271
  	rwlock_init(&mpc->ingress_lock);
  	rwlock_init(&mpc->egress_lock);
  	mpc->next = mpcs;
  	atm_mpoa_init_cache(mpc);
  
  	mpc->parameters.mpc_p1 = MPC_P1;
  	mpc->parameters.mpc_p2 = MPC_P2;
  	memset(mpc->parameters.mpc_p3,0,sizeof(mpc->parameters.mpc_p3));
  	mpc->parameters.mpc_p4 = MPC_P4;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
272
  	mpc->parameters.mpc_p5 = MPC_P5;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
273
  	mpc->parameters.mpc_p6 = MPC_P6;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
274

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
275
  	mpcs = mpc;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
276

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277
278
279
280
281
282
  	return mpc;
  }
  
  /*
   *
   * start_mpc() puts the MPC on line. All the packets destined
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
283
   * to the lec underneath us are now being monitored and
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
286
287
288
   * shortcuts will be established.
   *
   */
  static void start_mpc(struct mpoa_client *mpc, struct net_device *dev)
  {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
289
290
291
  
  	dprintk("mpoa: (%s) start_mpc:
  ", mpc->dev->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
293
294
295
296
297
298
299
300
301
302
303
304
305
  	if (dev->hard_start_xmit == NULL) {
  		printk("mpoa: (%s) start_mpc: dev->hard_start_xmit == NULL, not starting
  ",
  		       dev->name);
  		return;
  	}
  	mpc->old_hard_start_xmit = dev->hard_start_xmit;
  	dev->hard_start_xmit = mpc_send_packet;
  
  	return;
  }
  
  static void stop_mpc(struct mpoa_client *mpc)
  {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
306
307
  
  	dprintk("mpoa: (%s) stop_mpc:", mpc->dev->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
308
309
310
311
312
313
314
315
316
317
318
319
  
  	/* Lets not nullify lec device's dev->hard_start_xmit */
  	if (mpc->dev->hard_start_xmit != mpc_send_packet) {
  		dprintk(" mpc already stopped, not fatal
  ");
  		return;
  	}
  	dprintk("
  ");
  	mpc->dev->hard_start_xmit = mpc->old_hard_start_xmit;
  	mpc->old_hard_start_xmit = NULL;
  	/* close_shortcuts(mpc);    ??? FIXME */
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
320

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
  	return;
  }
  
  static const char *mpoa_device_type_string(char type) __attribute__ ((unused));
  
  static const char *mpoa_device_type_string(char type)
  {
  	switch(type) {
  	case NON_MPOA:
  		return "non-MPOA device";
  		break;
  	case MPS:
  		return "MPS";
  		break;
  	case MPC:
  		return "MPC";
  		break;
  	case MPS_AND_MPC:
  		return "both MPS and MPC";
  		break;
  	default:
  		return "unspecified (non-MPOA) device";
  		break;
  	}
  
  	return ""; /* not reached */
  }
  
  /*
   * lec device calls this via its dev->priv->lane2_ops->associate_indicator()
   * when it sees a TLV in LE_ARP packet.
   * We fill in the pointer above when we see a LANE2 lec initializing
   * See LANE2 spec 3.1.5
   *
   * Quite a big and ugly function but when you look at it
   * all it does is to try to locate and parse MPOA Device
   * Type TLV.
   * We give our lec a pointer to this function and when the
   * lec sees a TLV it uses the pointer to call this function.
   *
   */
  static void lane2_assoc_ind(struct net_device *dev, uint8_t *mac_addr,
  			    uint8_t *tlvs, uint32_t sizeoftlvs)
  {
  	uint32_t type;
  	uint8_t length, mpoa_device_type, number_of_mps_macs;
  	uint8_t *end_of_tlvs;
  	struct mpoa_client *mpc;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
369

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  	mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */
  	dprintk("mpoa: (%s) lane2_assoc_ind: received TLV(s), ", dev->name);
  	dprintk("total length of all TLVs %d
  ", sizeoftlvs);
  	mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */
  	if (mpc == NULL) {
  		printk("mpoa: (%s) lane2_assoc_ind: no mpc
  ", dev->name);
  		return;
  	}
  	end_of_tlvs = tlvs + sizeoftlvs;
  	while (end_of_tlvs - tlvs >= 5) {
  		type = (tlvs[0] << 24) | (tlvs[1] << 16) | (tlvs[2] << 8) | tlvs[3];
  		length = tlvs[4];
  		tlvs += 5;
  		dprintk("    type 0x%x length %02x
  ", type, length);
  		if (tlvs + length > end_of_tlvs) {
  			printk("TLV value extends past its buffer, aborting parse
  ");
  			return;
  		}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
392

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
  		if (type == 0) {
  			printk("mpoa: (%s) lane2_assoc_ind: TLV type was 0, returning
  ", dev->name);
  			return;
  		}
  
  		if (type != TLV_MPOA_DEVICE_TYPE) {
  			tlvs += length;
  			continue;  /* skip other TLVs */
  		}
  		mpoa_device_type = *tlvs++;
  		number_of_mps_macs = *tlvs++;
  		dprintk("mpoa: (%s) MPOA device type '%s', ", dev->name, mpoa_device_type_string(mpoa_device_type));
  		if (mpoa_device_type == MPS_AND_MPC &&
  		    length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */
  			printk("
  mpoa: (%s) lane2_assoc_ind: short MPOA Device Type TLV
  ",
  			       dev->name);
  			continue;
  		}
  		if ((mpoa_device_type == MPS || mpoa_device_type == MPC)
  		    && length < 22 + number_of_mps_macs*ETH_ALEN) {
  			printk("
  mpoa: (%s) lane2_assoc_ind: short MPOA Device Type TLV
  ",
  				dev->name);
  			continue;
  		}
  		if (mpoa_device_type != MPS && mpoa_device_type != MPS_AND_MPC) {
  			dprintk("ignoring non-MPS device
  ");
  			if (mpoa_device_type == MPC) tlvs += 20;
  			continue;  /* we are only interested in MPSs */
  		}
  		if (number_of_mps_macs == 0 && mpoa_device_type == MPS_AND_MPC) {
  			printk("
  mpoa: (%s) lane2_assoc_ind: MPS_AND_MPC has zero MACs
  ", dev->name);
  			continue;  /* someone should read the spec */
  		}
  		dprintk("this MPS has %d MAC addresses
  ", number_of_mps_macs);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
436

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
438
  		/* ok, now we can go and tell our daemon the control address of MPS */
  		send_set_mps_ctrl_addr(tlvs, mpc);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
439

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
  		tlvs = copy_macs(mpc, mac_addr, tlvs, number_of_mps_macs, mpoa_device_type);
  		if (tlvs == NULL) return;
  	}
  	if (end_of_tlvs - tlvs != 0)
  		printk("mpoa: (%s) lane2_assoc_ind: ignoring %Zd bytes of trailing TLV carbage
  ",
  		       dev->name, end_of_tlvs - tlvs);
  	return;
  }
  
  /*
   * Store at least advertizing router's MAC address
   * plus the possible MAC address(es) to mpc->mps_macs.
   * For a freshly allocated MPOA client mpc->mps_macs == 0.
   */
  static uint8_t *copy_macs(struct mpoa_client *mpc, uint8_t *router_mac,
  			  uint8_t *tlvs, uint8_t mps_macs, uint8_t device_type)
  {
  	int num_macs;
  	num_macs = (mps_macs > 1) ? mps_macs : 1;
  
  	if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */
  		if (mpc->number_of_mps_macs != 0) kfree(mpc->mps_macs);
  		mpc->number_of_mps_macs = 0;
  		mpc->mps_macs = kmalloc(num_macs*ETH_ALEN, GFP_KERNEL);
  		if (mpc->mps_macs == NULL) {
  			printk("mpoa: (%s) copy_macs: out of mem
  ", mpc->dev->name);
  			return NULL;
  		}
  	}
  	memcpy(mpc->mps_macs, router_mac, ETH_ALEN);
  	tlvs += 20; if (device_type == MPS_AND_MPC) tlvs += 20;
  	if (mps_macs > 0)
  		memcpy(mpc->mps_macs, tlvs, mps_macs*ETH_ALEN);
  	tlvs += mps_macs*ETH_ALEN;
  	mpc->number_of_mps_macs = num_macs;
  
  	return tlvs;
  }
  
  static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc)
  {
  	in_cache_entry *entry;
  	struct iphdr *iph;
  	char *buff;
30d492da7   Al Viro   [ATM]: Annotations.
486
  	__be32 ipaddr = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
487
488
489
  
  	static struct {
  		struct llc_snap_hdr hdr;
30d492da7   Al Viro   [ATM]: Annotations.
490
  		__be32 tag;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
491
492
493
494
495
496
497
498
  	} tagged_llc_snap_hdr = {
  		{0xaa, 0xaa, 0x03, {0x00, 0x00, 0x00}, {0x88, 0x4c}},
  		0
  	};
  
  	buff = skb->data + mpc->dev->hard_header_len;
  	iph = (struct iphdr *)buff;
  	ipaddr = iph->daddr;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
499
500
  	ddprintk("mpoa: (%s) send_via_shortcut: ipaddr 0x%x
  ", mpc->dev->name, ipaddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501
502
503
504
505
506
507
508
  
  	entry = mpc->in_ops->get(ipaddr, mpc);
  	if (entry == NULL) {
  		entry = mpc->in_ops->add_entry(ipaddr, mpc);
  		if (entry != NULL) mpc->in_ops->put(entry);
  		return 1;
  	}
  	if (mpc->in_ops->cache_hit(entry, mpc) != OPEN){   /* threshold not exceeded or VCC not ready */
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
509
510
  		ddprintk("mpoa: (%s) send_via_shortcut: cache_hit: returns != OPEN
  ", mpc->dev->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
511
512
513
  		mpc->in_ops->put(entry);
  		return 1;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
514
515
  	ddprintk("mpoa: (%s) send_via_shortcut: using shortcut
  ", mpc->dev->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
516
517
  	/* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */
  	if (iph->ttl <= 1) {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
518
519
  		ddprintk("mpoa: (%s) send_via_shortcut: IP ttl = %u, using LANE
  ", mpc->dev->name, iph->ttl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
520
521
522
523
524
525
526
527
528
529
530
531
532
  		mpc->in_ops->put(entry);
  		return 1;
  	}
  	iph->ttl--;
  	iph->check = 0;
  	iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
  
  	if (entry->ctrl_info.tag != 0) {
  		ddprintk("mpoa: (%s) send_via_shortcut: adding tag 0x%x
  ", mpc->dev->name, entry->ctrl_info.tag);
  		tagged_llc_snap_hdr.tag = entry->ctrl_info.tag;
  		skb_pull(skb, ETH_HLEN);                       /* get rid of Eth header */
  		skb_push(skb, sizeof(tagged_llc_snap_hdr));    /* add LLC/SNAP header   */
27d7ff46a   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
533
534
  		skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr,
  					sizeof(tagged_llc_snap_hdr));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
535
536
537
  	} else {
  		skb_pull(skb, ETH_HLEN);                        /* get rid of Eth header */
  		skb_push(skb, sizeof(struct llc_snap_hdr));     /* add LLC/SNAP header + tag  */
27d7ff46a   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
538
539
  		skb_copy_to_linear_data(skb, &llc_snap_mpoa_data,
  					sizeof(struct llc_snap_hdr));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
  	}
  
  	atomic_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc);
  	ATM_SKB(skb)->atm_options = entry->shortcut->atm_options;
  	entry->shortcut->send(entry->shortcut, skb);
  	entry->packets_fwded++;
  	mpc->in_ops->put(entry);
  
  	return 0;
  }
  
  /*
   * Probably needs some error checks and locking, not sure...
   */
  static int mpc_send_packet(struct sk_buff *skb, struct net_device *dev)
  {
  	int retval;
  	struct mpoa_client *mpc;
  	struct ethhdr *eth;
  	int i = 0;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
560

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
561
562
563
564
565
566
567
568
569
570
571
572
  	mpc = find_mpc_by_lec(dev); /* this should NEVER fail */
  	if(mpc == NULL) {
  		printk("mpoa: (%s) mpc_send_packet: no MPC found
  ", dev->name);
  		goto non_ip;
  	}
  
  	eth = (struct ethhdr *)skb->data;
  	if (eth->h_proto != htons(ETH_P_IP))
  		goto non_ip; /* Multi-Protocol Over ATM :-) */
  
  	while (i < mpc->number_of_mps_macs) {
d3f4a687f   Kris Katterjohn   [NET]: Change mem...
573
  		if (!compare_ether_addr(eth->h_dest, (mpc->mps_macs + i*ETH_ALEN)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
574
575
576
577
578
579
580
  			if ( send_via_shortcut(skb, mpc) == 0 )           /* try shortcut */
  				return 0;                                 /* success!     */
  		i++;
  	}
  
   non_ip:
  	retval = mpc->old_hard_start_xmit(skb,dev);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
581

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
582
583
584
585
586
587
588
589
590
  	return retval;
  }
  
  static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
  {
  	int bytes_left;
  	struct mpoa_client *mpc;
  	struct atmmpc_ioc ioc_data;
  	in_cache_entry *in_entry;
30d492da7   Al Viro   [ATM]: Annotations.
591
  	__be32  ipaddr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
592
593
594
595
596
597
598
599
600
601
  
  	bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc));
  	if (bytes_left != 0) {
  		printk("mpoa: mpc_vcc_attach: Short read (missed %d bytes) from userland
  ", bytes_left);
  		return -EFAULT;
  	}
  	ipaddr = ioc_data.ipaddr;
  	if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF)
  		return -EINVAL;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
602

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
603
604
605
  	mpc = find_mpc_by_itfnum(ioc_data.dev_num);
  	if (mpc == NULL)
  		return -EINVAL;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
606

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
607
608
609
610
611
612
613
614
615
  	if (ioc_data.type == MPC_SOCKET_INGRESS) {
  		in_entry = mpc->in_ops->get(ipaddr, mpc);
  		if (in_entry == NULL || in_entry->entry_state < INGRESS_RESOLVED) {
  			printk("mpoa: (%s) mpc_vcc_attach: did not find RESOLVED entry from ingress cache
  ",
  				mpc->dev->name);
  			if (in_entry != NULL) mpc->in_ops->put(in_entry);
  			return -EINVAL;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
616
617
  		printk("mpoa: (%s) mpc_vcc_attach: attaching ingress SVC, entry = %u.%u.%u.%u
  ",
b4229934b   Al Viro   [ATM]: use NIPQUA...
618
  		       mpc->dev->name, NIPQUAD(in_entry->ctrl_info.in_dst_ip));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
  		in_entry->shortcut = vcc;
  		mpc->in_ops->put(in_entry);
  	} else {
  		printk("mpoa: (%s) mpc_vcc_attach: attaching egress SVC
  ", mpc->dev->name);
  	}
  
  	vcc->proto_data = mpc->dev;
  	vcc->push = mpc_push;
  
  	return 0;
  }
  
  /*
   *
   */
  static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev)
  {
  	struct mpoa_client *mpc;
  	in_cache_entry *in_entry;
  	eg_cache_entry *eg_entry;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
640

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
641
642
643
644
645
646
647
648
649
650
651
  	mpc = find_mpc_by_lec(dev);
  	if (mpc == NULL) {
  		printk("mpoa: (%s) mpc_vcc_close: close for unknown MPC
  ", dev->name);
  		return;
  	}
  
  	dprintk("mpoa: (%s) mpc_vcc_close:
  ", dev->name);
  	in_entry = mpc->in_ops->get_by_vcc(vcc, mpc);
  	if (in_entry) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
652
653
  		dprintk("mpoa: (%s) mpc_vcc_close: ingress SVC closed ip = %u.%u.%u.%u
  ",
b4229934b   Al Viro   [ATM]: use NIPQUA...
654
  		       mpc->dev->name, NIPQUAD(in_entry->ctrl_info.in_dst_ip));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
  		in_entry->shortcut = NULL;
  		mpc->in_ops->put(in_entry);
  	}
  	eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc);
  	if (eg_entry) {
  		dprintk("mpoa: (%s) mpc_vcc_close: egress SVC closed
  ", mpc->dev->name);
  		eg_entry->shortcut = NULL;
  		mpc->eg_ops->put(eg_entry);
  	}
  
  	if (in_entry == NULL && eg_entry == NULL)
  		dprintk("mpoa: (%s) mpc_vcc_close:  unused vcc closed
  ", dev->name);
  
  	return;
  }
  
  static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
  {
  	struct net_device *dev = (struct net_device *)vcc->proto_data;
  	struct sk_buff *new_skb;
  	eg_cache_entry *eg;
  	struct mpoa_client *mpc;
30d492da7   Al Viro   [ATM]: Annotations.
679
  	__be32 tag;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
680
  	char *tmp;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
681

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
682
683
684
685
686
687
688
689
  	ddprintk("mpoa: (%s) mpc_push:
  ", dev->name);
  	if (skb == NULL) {
  		dprintk("mpoa: (%s) mpc_push: null skb, closing VCC
  ", dev->name);
  		mpc_vcc_close(vcc, dev);
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
690

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
  	skb->dev = dev;
  	if (memcmp(skb->data, &llc_snap_mpoa_ctrl, sizeof(struct llc_snap_hdr)) == 0) {
  		struct sock *sk = sk_atm(vcc);
  
  		dprintk("mpoa: (%s) mpc_push: control packet arrived
  ", dev->name);
  		/* Pass control packets to daemon */
  		skb_queue_tail(&sk->sk_receive_queue, skb);
  		sk->sk_data_ready(sk, skb->len);
  		return;
  	}
  
  	/* data coming over the shortcut */
  	atm_return(vcc, skb->truesize);
  
  	mpc = find_mpc_by_lec(dev);
  	if (mpc == NULL) {
  		printk("mpoa: (%s) mpc_push: unknown MPC
  ", dev->name);
  		return;
  	}
  
  	if (memcmp(skb->data, &llc_snap_mpoa_data_tagged, sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */
  		ddprintk("mpoa: (%s) mpc_push: tagged data packet arrived
  ", dev->name);
  
  	} else if (memcmp(skb->data, &llc_snap_mpoa_data, sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */
  		printk("mpoa: (%s) mpc_push: non-tagged data packet arrived
  ", dev->name);
  		printk("           mpc_push: non-tagged data unsupported, purging
  ");
  		dev_kfree_skb_any(skb);
  		return;
  	} else {
  		printk("mpoa: (%s) mpc_push: garbage arrived, purging
  ", dev->name);
  		dev_kfree_skb_any(skb);
  		return;
  	}
  
  	tmp = skb->data + sizeof(struct llc_snap_hdr);
30d492da7   Al Viro   [ATM]: Annotations.
732
  	tag = *(__be32 *)tmp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
733
734
735
736
737
738
739
740
741
742
  
  	eg = mpc->eg_ops->get_by_tag(tag, mpc);
  	if (eg == NULL) {
  		printk("mpoa: (%s) mpc_push: Didn't find egress cache entry, tag = %u
  ",
  		       dev->name,tag);
  		purge_egress_shortcut(vcc, NULL);
  		dev_kfree_skb_any(skb);
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
743

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
744
745
746
  	/*
  	 * See if ingress MPC is using shortcut we opened as a return channel.
  	 * This means we have a bi-directional vcc opened by us.
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
747
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
748
749
750
751
752
753
754
755
756
757
758
759
760
761
  	if (eg->shortcut == NULL) {
  		eg->shortcut = vcc;
  		printk("mpoa: (%s) mpc_push: egress SVC in use
  ", dev->name);
  	}
  
  	skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag)); /* get rid of LLC/SNAP header */
  	new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length); /* LLC/SNAP is shorter than MAC header :( */
  	dev_kfree_skb_any(skb);
  	if (new_skb == NULL){
  		mpc->eg_ops->put(eg);
  		return;
  	}
  	skb_push(new_skb, eg->ctrl_info.DH_length);     /* add MAC header */
27d7ff46a   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
762
763
  	skb_copy_to_linear_data(new_skb, eg->ctrl_info.DLL_header,
  				eg->ctrl_info.DH_length);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
764
  	new_skb->protocol = eth_type_trans(new_skb, dev);
c1d2bbe1c   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
765
  	skb_reset_network_header(new_skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
766

eddc9ec53   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
767
  	eg->latest_ip_addr = ip_hdr(new_skb)->saddr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
  	eg->packets_rcvd++;
  	mpc->eg_ops->put(eg);
  
  	memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
  	netif_rx(new_skb);
  
  	return;
  }
  
  static struct atmdev_ops mpc_ops = { /* only send is required */
  	.close	= mpoad_close,
  	.send	= msg_from_mpoad
  };
  
  static struct atm_dev mpc_dev = {
  	.ops	= &mpc_ops,
  	.type	= "mpc",
  	.number	= 42,
4ef8d0aea   Milind Arun Choudhary   [NET]: SPIN_LOCK_...
786
  	.lock	= __SPIN_LOCK_UNLOCKED(mpc_dev.lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
787
788
789
790
791
792
793
794
  	/* members not explicitly initialised will be 0 */
  };
  
  static int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg)
  {
  	struct mpoa_client *mpc;
  	struct lec_priv *priv;
  	int err;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
795

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
796
797
798
799
800
801
802
803
804
805
806
  	if (mpcs == NULL) {
  		init_timer(&mpc_timer);
  		mpc_timer_refresh();
  
  		/* This lets us now how our LECs are doing */
  		err = register_netdevice_notifier(&mpoa_notifier);
  		if (err < 0) {
  			del_timer(&mpc_timer);
  			return err;
  		}
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
807

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
  	mpc = find_mpc_by_itfnum(arg);
  	if (mpc == NULL) {
  		dprintk("mpoa: mpoad_attach: allocating new mpc for itf %d
  ", arg);
  		mpc = alloc_mpc();
  		if (mpc == NULL)
  			return -ENOMEM;
  		mpc->dev_num = arg;
  		mpc->dev = find_lec_by_itfnum(arg); /* NULL if there was no lec */
  	}
  	if (mpc->mpoad_vcc) {
  		printk("mpoa: mpoad_attach: mpoad is already present for itf %d
  ", arg);
  		return -EADDRINUSE;
  	}
  
  	if (mpc->dev) { /* check if the lec is LANE2 capable */
  		priv = (struct lec_priv *)mpc->dev->priv;
  		if (priv->lane_version < 2) {
  			dev_put(mpc->dev);
  			mpc->dev = NULL;
  		} else
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
830
  			priv->lane2_ops->associate_indicator = lane2_assoc_ind;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
831
832
833
834
835
836
837
838
839
840
841
  	}
  
  	mpc->mpoad_vcc = vcc;
  	vcc->dev = &mpc_dev;
  	vcc_insert_socket(sk_atm(vcc));
  	set_bit(ATM_VF_META,&vcc->flags);
  	set_bit(ATM_VF_READY,&vcc->flags);
  
  	if (mpc->dev) {
  		char empty[ATM_ESA_LEN];
  		memset(empty, 0, ATM_ESA_LEN);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
842

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
  		start_mpc(mpc, mpc->dev);
  		/* set address if mpcd e.g. gets killed and restarted.
  		 * If we do not do it now we have to wait for the next LE_ARP
  		 */
  		if ( memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0 )
  			send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc);
  	}
  
  	__module_get(THIS_MODULE);
  	return arg;
  }
  
  static void send_set_mps_ctrl_addr(char *addr, struct mpoa_client *mpc)
  {
  	struct k_message mesg;
  
  	memcpy (mpc->mps_ctrl_addr, addr, ATM_ESA_LEN);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
860

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
  	mesg.type = SET_MPS_CTRL_ADDR;
  	memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN);
  	msg_to_mpoad(&mesg, mpc);
  
  	return;
  }
  
  static void mpoad_close(struct atm_vcc *vcc)
  {
  	struct mpoa_client *mpc;
  	struct sk_buff *skb;
  
  	mpc = find_mpc_by_vcc(vcc);
  	if (mpc == NULL) {
  		printk("mpoa: mpoad_close: did not find MPC
  ");
  		return;
  	}
  	if (!mpc->mpoad_vcc) {
  		printk("mpoa: mpoad_close: close for non-present mpoad
  ");
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
884

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
  	mpc->mpoad_vcc = NULL;
  	if (mpc->dev) {
  		struct lec_priv *priv = (struct lec_priv *)mpc->dev->priv;
  		priv->lane2_ops->associate_indicator = NULL;
  		stop_mpc(mpc);
  		dev_put(mpc->dev);
  	}
  
  	mpc->in_ops->destroy_cache(mpc);
  	mpc->eg_ops->destroy_cache(mpc);
  
  	while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
  		atm_return(vcc, skb->truesize);
  		kfree_skb(skb);
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
900

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
901
902
903
904
905
906
907
908
909
910
911
912
913
  	printk("mpoa: (%s) going down
  ",
  		(mpc->dev) ? mpc->dev->name : "<unknown>");
  	module_put(THIS_MODULE);
  
  	return;
  }
  
  /*
   *
   */
  static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb)
  {
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
914

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
915
916
917
  	struct mpoa_client *mpc = find_mpc_by_vcc(vcc);
  	struct k_message *mesg = (struct k_message*)skb->data;
  	atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
918

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
  	if (mpc == NULL) {
  		printk("mpoa: msg_from_mpoad: no mpc found
  ");
  		return 0;
  	}
  	dprintk("mpoa: (%s) msg_from_mpoad:", (mpc->dev) ? mpc->dev->name : "<unknown>");
  	switch(mesg->type) {
  	case MPOA_RES_REPLY_RCVD:
  		dprintk(" mpoa_res_reply_rcvd
  ");
  		MPOA_res_reply_rcvd(mesg, mpc);
  		break;
  	case MPOA_TRIGGER_RCVD:
  		dprintk(" mpoa_trigger_rcvd
  ");
  		MPOA_trigger_rcvd(mesg, mpc);
  		break;
  	case INGRESS_PURGE_RCVD:
  		dprintk(" nhrp_purge_rcvd
  ");
  		ingress_purge_rcvd(mesg, mpc);
  		break;
  	case EGRESS_PURGE_RCVD:
  		dprintk(" egress_purge_reply_rcvd
  ");
  		egress_purge_rcvd(mesg, mpc);
  		break;
  	case MPS_DEATH:
  		dprintk(" mps_death
  ");
  		mps_death(mesg, mpc);
  		break;
  	case CACHE_IMPOS_RCVD:
  		dprintk(" cache_impos_rcvd
  ");
  		MPOA_cache_impos_rcvd(mesg, mpc);
  		break;
  	case SET_MPC_CTRL_ADDR:
  		dprintk(" set_mpc_ctrl_addr
  ");
  		set_mpc_ctrl_addr_rcvd(mesg, mpc);
  		break;
  	case SET_MPS_MAC_ADDR:
  		dprintk(" set_mps_mac_addr
  ");
  		set_mps_mac_addr_rcvd(mesg, mpc);
  		break;
  	case CLEAN_UP_AND_EXIT:
  		dprintk(" clean_up_and_exit
  ");
  		clean_up(mesg, mpc, DIE);
  		break;
  	case RELOAD:
  		dprintk(" reload
  ");
  		clean_up(mesg, mpc, RELOAD);
  		break;
  	case SET_MPC_PARAMS:
  		dprintk(" set_mpc_params
  ");
  		mpc->parameters = mesg->content.params;
  		break;
  	default:
  		dprintk(" unknown message %d
  ", mesg->type);
  		break;
  	}
  	kfree_skb(skb);
  
  	return 0;
  }
  
  /* Remember that this function may not do things that sleep */
  int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
  {
  	struct sk_buff *skb;
  	struct sock *sk;
  
  	if (mpc == NULL || !mpc->mpoad_vcc) {
  		printk("mpoa: msg_to_mpoad: mesg %d to a non-existent mpoad
  ", mesg->type);
  		return -ENXIO;
  	}
  
  	skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  	if (skb == NULL)
  		return -ENOMEM;
  	skb_put(skb, sizeof(struct k_message));
27d7ff46a   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
1007
  	skb_copy_to_linear_data(skb, mesg, sizeof(*mesg));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1008
  	atm_force_charge(mpc->mpoad_vcc, skb->truesize);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1009

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
  	sk = sk_atm(mpc->mpoad_vcc);
  	skb_queue_tail(&sk->sk_receive_queue, skb);
  	sk->sk_data_ready(sk, skb->len);
  
  	return 0;
  }
  
  static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned long event, void *dev_ptr)
  {
  	struct net_device *dev;
  	struct mpoa_client *mpc;
  	struct lec_priv *priv;
  
  	dev = (struct net_device *)dev_ptr;
  	if (dev->name == NULL || strncmp(dev->name, "lec", 3))
  		return NOTIFY_DONE; /* we are only interested in lec:s */
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1026

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
  	switch (event) {
  	case NETDEV_REGISTER:       /* a new lec device was allocated */
  		priv = (struct lec_priv *)dev->priv;
  		if (priv->lane_version < 2)
  			break;
  		priv->lane2_ops->associate_indicator = lane2_assoc_ind;
  		mpc = find_mpc_by_itfnum(priv->itfnum);
  		if (mpc == NULL) {
  			dprintk("mpoa: mpoa_event_listener: allocating new mpc for %s
  ",
  			       dev->name);
  			mpc = alloc_mpc();
  			if (mpc == NULL) {
  				printk("mpoa: mpoa_event_listener: no new mpc");
  				break;
  			}
  		}
  		mpc->dev_num = priv->itfnum;
  		mpc->dev = dev;
  		dev_hold(dev);
  		dprintk("mpoa: (%s) was initialized
  ", dev->name);
  		break;
  	case NETDEV_UNREGISTER:
  		/* the lec device was deallocated */
  		mpc = find_mpc_by_lec(dev);
  		if (mpc == NULL)
  			break;
  		dprintk("mpoa: device (%s) was deallocated
  ", dev->name);
  		stop_mpc(mpc);
  		dev_put(mpc->dev);
  		mpc->dev = NULL;
  		break;
  	case NETDEV_UP:
  		/* the dev was ifconfig'ed up */
  		mpc = find_mpc_by_lec(dev);
  		if (mpc == NULL)
  			break;
  		if (mpc->mpoad_vcc != NULL) {
  			start_mpc(mpc, dev);
  		}
  		break;
  	case NETDEV_DOWN:
  		/* the dev was ifconfig'ed down */
  		/* this means that the flow of packets from the
  		 * upper layer stops
  		 */
  		mpc = find_mpc_by_lec(dev);
  		if (mpc == NULL)
  			break;
  		if (mpc->mpoad_vcc != NULL) {
  			stop_mpc(mpc);
  		}
  		break;
  	case NETDEV_REBOOT:
  	case NETDEV_CHANGE:
  	case NETDEV_CHANGEMTU:
  	case NETDEV_CHANGEADDR:
  	case NETDEV_GOING_DOWN:
  		break;
  	default:
  		break;
  	}
  
  	return NOTIFY_DONE;
  }
  
  /*
   * Functions which are called after a message is received from mpcd.
   * Msg is reused on purpose.
   */
  
  
  static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  {
30d492da7   Al Viro   [ATM]: Annotations.
1103
  	__be32 dst_ip = msg->content.in_info.in_dst_ip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
  	in_cache_entry *entry;
  
  	entry = mpc->in_ops->get(dst_ip, mpc);
  	if(entry == NULL){
  		entry = mpc->in_ops->add_entry(dst_ip, mpc);
  		entry->entry_state = INGRESS_RESOLVING;
  		msg->type = SND_MPOA_RES_RQST;
  		msg->content.in_info = entry->ctrl_info;
  		msg_to_mpoad(msg, mpc);
  		do_gettimeofday(&(entry->reply_wait));
  		mpc->in_ops->put(entry);
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1117

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1118
1119
1120
1121
1122
1123
1124
1125
1126
  	if(entry->entry_state == INGRESS_INVALID){
  		entry->entry_state = INGRESS_RESOLVING;
  		msg->type = SND_MPOA_RES_RQST;
  		msg->content.in_info = entry->ctrl_info;
  		msg_to_mpoad(msg, mpc);
  		do_gettimeofday(&(entry->reply_wait));
  		mpc->in_ops->put(entry);
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1127

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1128
1129
1130
1131
1132
1133
1134
1135
1136
  	printk("mpoa: (%s) MPOA_trigger_rcvd: entry already in resolving state
  ",
  		(mpc->dev) ? mpc->dev->name : "<unknown>");
  	mpc->in_ops->put(entry);
  	return;
  }
  
  /*
   * Things get complicated because we have to check if there's an egress
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1137
   * shortcut with suitable traffic parameters we could use.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1138
1139
1140
   */
  static void check_qos_and_open_shortcut(struct k_message *msg, struct mpoa_client *client, in_cache_entry *entry)
  {
30d492da7   Al Viro   [ATM]: Annotations.
1141
  	__be32 dst_ip = msg->content.in_info.in_dst_ip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
  	struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip);
  	eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client);
  
  	if(eg_entry && eg_entry->shortcut){
  		if(eg_entry->shortcut->qos.txtp.traffic_class &
  		   msg->qos.txtp.traffic_class &
  		   (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)){
  			    if(eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR)
  				    entry->shortcut = eg_entry->shortcut;
  			    else if(eg_entry->shortcut->qos.txtp.max_pcr > 0)
  				    entry->shortcut = eg_entry->shortcut;
  		}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1154
  		if(entry->shortcut){
ff7512e1a   Al Viro   [ATM]: fix broken...
1155
1156
  			dprintk("mpoa: (%s) using egress SVC to reach %u.%u.%u.%u
  ",client->dev->name, NIPQUAD(dst_ip));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
  			client->eg_ops->put(eg_entry);
  			return;
  		}
  	}
  	if (eg_entry != NULL)
  		client->eg_ops->put(eg_entry);
  
  	/* No luck in the egress cache we must open an ingress SVC */
  	msg->type = OPEN_INGRESS_SVC;
  	if (qos && (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class))
  	{
  		msg->qos = qos->qos;
  		printk("mpoa: (%s) trying to get a CBR shortcut
  ",client->dev->name);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1171
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1172
1173
1174
1175
1176
1177
1178
  	else memset(&msg->qos,0,sizeof(struct atm_qos));
  	msg_to_mpoad(msg, client);
  	return;
  }
  
  static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  {
30d492da7   Al Viro   [ATM]: Annotations.
1179
  	__be32 dst_ip = msg->content.in_info.in_dst_ip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1180
  	in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc);
1e4fd51e2   Andrew Morton   [ATM]: atm/mpc.c ...
1181

ff7512e1a   Al Viro   [ATM]: fix broken...
1182
1183
  	dprintk("mpoa: (%s) MPOA_res_reply_rcvd: ip %u.%u.%u.%u
  ", mpc->dev->name, NIPQUAD(dst_ip));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1184
1185
1186
1187
1188
1189
1190
  	ddprintk("mpoa: (%s) MPOA_res_reply_rcvd() entry = %p", mpc->dev->name, entry);
  	if(entry == NULL){
  		printk("
  mpoa: (%s) ARGH, received res. reply for an entry that doesn't exist.
  ", mpc->dev->name);
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1191
  	ddprintk(" entry_state = %d ", entry->entry_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
  
  	if (entry->entry_state == INGRESS_RESOLVED) {
  		printk("
  mpoa: (%s) MPOA_res_reply_rcvd for RESOLVED entry!
  ", mpc->dev->name);
  		mpc->in_ops->put(entry);
  		return;
  	}
  
  	entry->ctrl_info = msg->content.in_info;
  	do_gettimeofday(&(entry->tv));
  	do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */
  	entry->refresh_time = 0;
  	ddprintk("entry->shortcut = %p
  ", entry->shortcut);
  
  	if(entry->entry_state == INGRESS_RESOLVING && entry->shortcut != NULL){
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1209
  		entry->entry_state = INGRESS_RESOLVED;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
  		mpc->in_ops->put(entry);
  		return; /* Shortcut already open... */
  	}
  
  	if (entry->shortcut != NULL) {
  		printk("mpoa: (%s) MPOA_res_reply_rcvd: entry->shortcut != NULL, impossible!
  ",
  		       mpc->dev->name);
  		mpc->in_ops->put(entry);
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1221

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
  	check_qos_and_open_shortcut(msg, mpc, entry);
  	entry->entry_state = INGRESS_RESOLVED;
  	mpc->in_ops->put(entry);
  
  	return;
  
  }
  
  static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  {
30d492da7   Al Viro   [ATM]: Annotations.
1232
1233
  	__be32 dst_ip = msg->content.in_info.in_dst_ip;
  	__be32 mask = msg->ip_mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1234
1235
1236
1237
  	in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  
  	if(entry == NULL){
  		printk("mpoa: (%s) ingress_purge_rcvd: purge for a non-existing entry, ", mpc->dev->name);
b4229934b   Al Viro   [ATM]: use NIPQUA...
1238
1239
  		printk("ip = %u.%u.%u.%u
  ", NIPQUAD(dst_ip));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1240
1241
1242
1243
1244
1245
  		return;
  	}
  
  	do {
  		dprintk("mpoa: (%s) ingress_purge_rcvd: removing an ingress entry, ip = %u.%u.%u.%u
  " ,
b4229934b   Al Viro   [ATM]: use NIPQUA...
1246
  			mpc->dev->name, NIPQUAD(dst_ip));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1247
1248
1249
1250
1251
1252
1253
1254
  		write_lock_bh(&mpc->ingress_lock);
  		mpc->in_ops->remove_entry(entry, mpc);
  		write_unlock_bh(&mpc->ingress_lock);
  		mpc->in_ops->put(entry);
  		entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  	} while (entry != NULL);
  
  	return;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1255
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1256
1257
1258
  
  static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  {
30d492da7   Al Viro   [ATM]: Annotations.
1259
  	__be32 cache_id = msg->content.eg_info.cache_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1260
  	eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1261

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
  	if (entry == NULL) {
  		dprintk("mpoa: (%s) egress_purge_rcvd: purge for a non-existing entry
  ", mpc->dev->name);
  		return;
  	}
  
  	write_lock_irq(&mpc->egress_lock);
  	mpc->eg_ops->remove_entry(entry, mpc);
  	write_unlock_irq(&mpc->egress_lock);
  
  	mpc->eg_ops->put(entry);
  
  	return;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1275
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
  
  static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
  {
  	struct sock *sk;
  	struct k_message *purge_msg;
  	struct sk_buff *skb;
  
  	dprintk("mpoa: purge_egress_shortcut: entering
  ");
  	if (vcc == NULL) {
  		printk("mpoa: purge_egress_shortcut: vcc == NULL
  ");
  		return;
  	}
  
  	skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  	if (skb == NULL) {
  		 printk("mpoa: purge_egress_shortcut: out of memory
  ");
  		return;
  	}
  
  	skb_put(skb, sizeof(struct k_message));
  	memset(skb->data, 0, sizeof(struct k_message));
  	purge_msg = (struct k_message *)skb->data;
  	purge_msg->type = DATA_PLANE_PURGE;
  	if (entry != NULL)
  		purge_msg->content.eg_info = entry->ctrl_info;
  
  	atm_force_charge(vcc, skb->truesize);
  
  	sk = sk_atm(vcc);
  	skb_queue_tail(&sk->sk_receive_queue, skb);
  	sk->sk_data_ready(sk, skb->len);
  	dprintk("mpoa: purge_egress_shortcut: exiting:
  ");
  
  	return;
  }
  
  /*
   * Our MPS died. Tell our daemon to send NHRP data plane purge to each
   * of the egress shortcuts we have.
   */
  static void mps_death( struct k_message * msg, struct mpoa_client * mpc )
  {
  	eg_cache_entry *entry;
  
  	dprintk("mpoa: (%s) mps_death:
  ", mpc->dev->name);
  
  	if(memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)){
  		printk("mpoa: (%s) mps_death: wrong MPS
  ", mpc->dev->name);
  		return;
  	}
  
  	/* FIXME: This knows too much of the cache structure */
  	read_lock_irq(&mpc->egress_lock);
  	entry = mpc->eg_cache;
  	while (entry != NULL) {
  		purge_egress_shortcut(entry->shortcut, entry);
  		entry = entry->next;
  	}
  	read_unlock_irq(&mpc->egress_lock);
  
  	mpc->in_ops->destroy_cache(mpc);
  	mpc->eg_ops->destroy_cache(mpc);
  
  	return;
  }
  
  static void MPOA_cache_impos_rcvd( struct k_message * msg, struct mpoa_client * mpc)
  {
  	uint16_t holding_time;
  	eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1352

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
  	holding_time = msg->content.eg_info.holding_time;
  	dprintk("mpoa: (%s) MPOA_cache_impos_rcvd: entry = %p, holding_time = %u
  ",
  	       mpc->dev->name, entry, holding_time);
  	if(entry == NULL && holding_time) {
  		entry = mpc->eg_ops->add_entry(msg, mpc);
  		mpc->eg_ops->put(entry);
  		return;
  	}
  	if(holding_time){
  		mpc->eg_ops->update(entry, holding_time);
  		return;
  	}
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1366

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1367
1368
1369
1370
1371
  	write_lock_irq(&mpc->egress_lock);
  	mpc->eg_ops->remove_entry(entry, mpc);
  	write_unlock_irq(&mpc->egress_lock);
  
  	mpc->eg_ops->put(entry);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1372

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
  	return;
  }
  
  static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, struct mpoa_client *mpc)
  {
  	struct lec_priv *priv;
  	int i, retval ;
  
  	uint8_t tlv[4 + 1 + 1 + 1 + ATM_ESA_LEN];
  
  	tlv[0] = 00; tlv[1] = 0xa0; tlv[2] = 0x3e; tlv[3] = 0x2a; /* type  */
  	tlv[4] = 1 + 1 + ATM_ESA_LEN;  /* length                           */
  	tlv[5] = 0x02;                 /* MPOA client                      */
  	tlv[6] = 0x00;                 /* number of MPS MAC addresses      */
  
  	memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */
  	memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN);
  
  	dprintk("mpoa: (%s) setting MPC ctrl ATM address to ",
  	       (mpc->dev) ? mpc->dev->name : "<unknown>");
  	for (i = 7; i < sizeof(tlv); i++)
  		dprintk("%02x ", tlv[i]);
  	dprintk("
  ");
  
  	if (mpc->dev) {
  		priv = (struct lec_priv *)mpc->dev->priv;
  		retval = priv->lane2_ops->associate_req(mpc->dev, mpc->dev->dev_addr, tlv, sizeof(tlv));
  		if (retval == 0)
  			printk("mpoa: (%s) MPOA device type TLV association failed
  ", mpc->dev->name);
  		retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL);
  		if (retval < 0)
  			printk("mpoa: (%s) targetless LE_ARP request failed
  ", mpc->dev->name);
  	}
  
  	return;
  }
  
  static void set_mps_mac_addr_rcvd(struct k_message *msg, struct mpoa_client *client)
  {
  
  	if(client->number_of_mps_macs)
  		kfree(client->mps_macs);
  	client->number_of_mps_macs = 0;
2afe37cdf   Arnaldo Carvalho de Melo   [ATM]: Use kmemdu...
1419
  	client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1420
1421
1422
1423
1424
1425
  	if (client->mps_macs == NULL) {
  		printk("mpoa: set_mps_mac_addr_rcvd: out of memory
  ");
  		return;
  	}
  	client->number_of_mps_macs = 1;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1426

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
  	return;
  }
  
  /*
   * purge egress cache and tell daemon to 'action' (DIE, RELOAD)
   */
  static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action)
  {
  
  	eg_cache_entry *entry;
  	msg->type = SND_EGRESS_PURGE;
  
  
  	/* FIXME: This knows too much of the cache structure */
  	read_lock_irq(&mpc->egress_lock);
  	entry = mpc->eg_cache;
  	while (entry != NULL){
  		    msg->content.eg_info = entry->ctrl_info;
  		    dprintk("mpoa: cache_id %u
  ", entry->ctrl_info.cache_id);
  		    msg_to_mpoad(msg, mpc);
  		    entry = entry->next;
  	}
  	read_unlock_irq(&mpc->egress_lock);
  
  	msg->type = action;
  	msg_to_mpoad(msg, mpc);
  	return;
  }
  
  static void mpc_timer_refresh(void)
  {
  	mpc_timer.expires = jiffies + (MPC_P2 * HZ);
  	mpc_timer.data = mpc_timer.expires;
  	mpc_timer.function = mpc_cache_check;
  	add_timer(&mpc_timer);
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1463

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1464
1465
1466
1467
1468
1469
1470
1471
  	return;
  }
  
  static void mpc_cache_check( unsigned long checking_time  )
  {
  	struct mpoa_client *mpc = mpcs;
  	static unsigned long previous_resolving_check_time;
  	static unsigned long previous_refresh_time;
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1472

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
  	while( mpc != NULL ){
  		mpc->in_ops->clear_count(mpc);
  		mpc->eg_ops->clear_expired(mpc);
  		if(checking_time - previous_resolving_check_time > mpc->parameters.mpc_p4 * HZ ){
  			mpc->in_ops->check_resolving(mpc);
  			previous_resolving_check_time = checking_time;
  		}
  		if(checking_time - previous_refresh_time > mpc->parameters.mpc_p5 * HZ ){
  			mpc->in_ops->refresh(mpc);
  			previous_refresh_time = checking_time;
  		}
  		mpc = mpc->next;
  	}
  	mpc_timer_refresh();
f7d57453d   YOSHIFUJI Hideaki   [NET] ATM: Fix wh...
1487

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
  	return;
  }
  
  static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  {
  	int err = 0;
  	struct atm_vcc *vcc = ATM_SD(sock);
  
  	if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA)
  		return -ENOIOCTLCMD;
  
  	if (!capable(CAP_NET_ADMIN))
  		return -EPERM;
  
  	switch (cmd) {
  		case ATMMPC_CTRL:
  			err = atm_mpoa_mpoad_attach(vcc, (int)arg);
  			if (err >= 0)
  				sock->state = SS_CONNECTED;
  			break;
  		case ATMMPC_DATA:
  			err = atm_mpoa_vcc_attach(vcc, (void __user *)arg);
  			break;
  		default:
  			break;
  	}
  	return err;
  }
  
  
  static struct atm_ioctl atm_ioctl_ops = {
  	.owner	= THIS_MODULE,
  	.ioctl	= atm_mpoa_ioctl,
  };
  
  static __init int atm_mpoa_init(void)
  {
  	register_atm_ioctl(&atm_ioctl_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1526
1527
1528
  	if (mpc_proc_init() != 0)
  		printk(KERN_INFO "mpoa: failed to initialize /proc/mpoa
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
  
  	printk("mpc.c: " __DATE__ " " __TIME__ " initialized
  ");
  
  	return 0;
  }
  
  static void __exit atm_mpoa_cleanup(void)
  {
  	struct mpoa_client *mpc, *tmp;
  	struct atm_mpoa_qos *qos, *nextqos;
  	struct lec_priv *priv;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1541
  	mpc_proc_clean();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
  
  	del_timer(&mpc_timer);
  	unregister_netdevice_notifier(&mpoa_notifier);
  	deregister_atm_ioctl(&atm_ioctl_ops);
  
  	mpc = mpcs;
  	mpcs = NULL;
  	while (mpc != NULL) {
  		tmp = mpc->next;
  		if (mpc->dev != NULL) {
  			stop_mpc(mpc);
  			priv = (struct lec_priv *)mpc->dev->priv;
  			if (priv->lane2_ops != NULL)
  				priv->lane2_ops->associate_indicator = NULL;
  		}
  		ddprintk("mpoa: cleanup_module: about to clear caches
  ");
  		mpc->in_ops->destroy_cache(mpc);
  		mpc->eg_ops->destroy_cache(mpc);
  		ddprintk("mpoa: cleanup_module: caches cleared
  ");
  		kfree(mpc->mps_macs);
  		memset(mpc, 0, sizeof(struct mpoa_client));
  		ddprintk("mpoa: cleanup_module: about to kfree %p
  ", mpc);
  		kfree(mpc);
  		ddprintk("mpoa: cleanup_module: next mpc is at %p
  ", tmp);
  		mpc = tmp;
  	}
  
  	qos = qos_head;
  	qos_head = NULL;
  	while (qos != NULL) {
  		nextqos = qos->next;
  		dprintk("mpoa: cleanup_module: freeing qos entry %p
  ", qos);
  		kfree(qos);
  		qos = nextqos;
  	}
  
  	return;
  }
  
  module_init(atm_mpoa_init);
  module_exit(atm_mpoa_cleanup);
  
  MODULE_LICENSE("GPL");