1 /* PPPoE support library "libpppoe"
3 * Copyright 2000 Michal Ostrowski <mostrows@styx.uwaterloo.ca>,
4 * Jamal Hadi Salim <hadi@cyberus.ca>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
14 #define PPPOE_HASH_SIZE 16
17 static inline int keycmp(char *a
, char *b
, int x
, int y
){
18 return x
==y
&& !memcmp(a
,b
,x
);
21 static int hash_con(int key_len
, char* key
)
24 char hash
[sizeof(int)]={0,};
26 for (i
= 0; i
< key_len
; ++i
)
27 hash
[i
% sizeof(int)] = hash
[i
%sizeof(int)] ^ key
[i
];
30 i
&= PPPOE_HASH_SIZE
- 1;
35 static struct pppoe_con
*con_ht
[PPPOE_HASH_SIZE
] = { 0, };
37 struct pppoe_con
*get_con(int len
, char *key
)
39 int hash
= hash_con(len
, key
);
40 struct pppoe_con
*ret
;
44 while (ret
&& !keycmp(ret
->key
,key
, ret
->key_len
, len
))
50 int store_con(struct pppoe_con
*pc
)
52 int hash
= hash_con(pc
->key_len
, pc
->key
);
53 struct pppoe_con
*ret
;
57 if (!keycmp(ret
->key
, pc
->key
, ret
->key_len
, pc
->key_len
))
64 pc
->next
= con_ht
[hash
];
71 struct pppoe_con
*delete_con(unsigned long len
, char *key
)
73 int hash
= hash_con(len
, key
);
74 struct pppoe_con
*ret
, **src
;
80 if (keycmp(ret
->key
,key
, ret
->key_len
, len
)) {