Collapse gd_astpending and gd_reqpri together into gd_reqflags. gd_reqflags
[dragonfly.git] / lib / libatm / cache_key.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  * $FreeBSD: src/lib/libatm/cache_key.c,v 1.3.2.1 2001/09/28 16:52:10 dillon Exp $
27  * $DragonFly: src/lib/libatm/cache_key.c,v 1.2 2003/06/17 04:26:41 dillon Exp $
28  */
29
30 /*
31  * User Space Library Functions
32  * ----------------------------
33  *
34  * SCSP cache key computation
35  *
36  */
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42 #include <netinet/in.h>
43 #include <netatm/port.h>
44 #include <netatm/atm.h>
45 #include <netatm/atm_if.h>
46 #include <netatm/atm_sap.h>
47 #include <netatm/atm_sys.h>
48 #include <netatm/atm_ioctl.h>
49
50 #include <md5.h>
51 #include <string.h>
52
53 #include "libatm.h"
54
55 /*
56  * Compute an SCSP cache key
57  *
58  * Arguments:
59  *      ap      pointer to an Atm_addr with the ATM address
60  *      ip      pointer to a struct in_addr with the IP address
61  *      ol      the required length of the cache key
62  *      op      pointer to receive cache key
63  *
64  * Returns:
65  *      none
66  *
67  */
68 void
69 scsp_cache_key(ap, ip, ol, op)
70         Atm_addr        *ap;
71         struct in_addr  *ip;
72         int             ol;
73         char            *op;
74 {
75         int     i, len;
76         char    buff[32], digest[16];
77         MD5_CTX context;
78
79         /*
80          * Initialize
81          */
82         UM_ZERO(buff, sizeof(buff));
83
84         /*
85          * Copy the addresses into a buffer for MD5 computation
86          */
87         len = sizeof(struct in_addr) + ap->address_length;
88         if (len > sizeof(buff))
89                 len = sizeof(buff);
90         UM_COPY(ip, buff, sizeof(struct in_addr));
91         UM_COPY(ap->address, &buff[sizeof(struct in_addr)],
92                         len - sizeof(struct in_addr));
93
94         /*
95          * Compute the MD5 digest of the combined IP and ATM addresses
96          */
97         MD5Init(&context);
98         MD5Update(&context, buff, len);
99         MD5Final(digest, &context);
100
101         /*
102          * Fold the 16-byte digest to the required length
103          */
104         UM_ZERO((caddr_t)op, ol);
105         for (i = 0; i < 16; i++) {
106                 op[i % ol] = op[i % ol] ^ digest[i];
107         }
108 }