4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Routines to handle getipnode* calls in nscd. Note that the
30 * getnodeby* APIs were renamed getipnodeby*. The interfaces
31 * related to them in the nscd will remain as getnode*.
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
44 static int ipaddr_compar(const void *, const void *);
45 static uint_t
ipaddr_gethash(nss_XbyY_key_t
*, int);
46 static void ipaddr_getlogstr(char *, char *, size_t, nss_XbyY_args_t
*);
48 static int ipname_compar(const void *, const void *);
49 static uint_t
ipname_gethash(nss_XbyY_key_t
*, int);
50 static void ipname_getlogstr(char *, char *, size_t, nss_XbyY_args_t
*);
52 #define nnam_db ctx->nsc_db[0]
53 #define addr_db ctx->nsc_db[1]
55 #define NSC_NAME_IPNODES_BYNAME "getipnodebyname"
56 #define NSC_NAME_IPNODES_BYADDR "getipnodebyaddr"
59 ipnode_init_ctx(nsc_ctx_t
*ctx
) {
60 ctx
->dbname
= NSS_DBNAM_IPNODES
;
61 ctx
->file_name
= "/etc/inet/ipnodes";
63 nnam_db
= make_cache(nsc_key_other
,
64 NSS_DBOP_IPNODES_BYNAME
,
65 NSC_NAME_IPNODES_BYNAME
,
68 ipname_gethash
, nsc_ht_default
, -1);
70 addr_db
= make_cache(nsc_key_other
,
71 NSS_DBOP_IPNODES_BYADDR
,
72 NSC_NAME_IPNODES_BYADDR
,
75 ipaddr_gethash
, nsc_ht_default
, -1);
79 ipaddr_compar(const void *n1
, const void *n2
) {
83 e1
= (nsc_entry_t
*)n1
;
84 e2
= (nsc_entry_t
*)n2
;
86 if (e1
->key
.hostaddr
.type
> e2
->key
.hostaddr
.type
)
88 else if (e1
->key
.hostaddr
.type
< e2
->key
.hostaddr
.type
)
91 l1
= e1
->key
.hostaddr
.len
;
92 l2
= e2
->key
.hostaddr
.len
;
93 res
= memcmp(e1
->key
.hostaddr
.addr
, e2
->key
.hostaddr
.addr
,
95 return ((res
) ? _NSC_INT_KEY_CMP(res
, 0) : _NSC_INT_KEY_CMP(l1
, l2
));
99 ipaddr_gethash(nss_XbyY_key_t
*key
, int htsize
) {
100 return (db_gethash(key
->hostaddr
.addr
,
101 key
->hostaddr
.len
, htsize
));
105 ipaddr_getlogstr(char *name
, char *whoami
, size_t len
, nss_XbyY_args_t
*argp
) {
106 char addr
[INET6_ADDRSTRLEN
];
108 if (inet_ntop(argp
->key
.hostaddr
.type
, argp
->key
.hostaddr
.addr
, addr
,
109 sizeof (addr
)) == NULL
) {
110 (void) snprintf(whoami
, len
, "%s", name
);
112 (void) snprintf(whoami
, len
, "%s [key=%s addrtype=%d]",
114 addr
, argp
->key
.hostaddr
.type
);
119 ipname_compar(const void *n1
, const void *n2
) {
120 nsc_entry_t
*e1
, *e2
;
123 e1
= (nsc_entry_t
*)n1
;
124 e2
= (nsc_entry_t
*)n2
;
126 if (e1
->key
.ipnode
.af_family
> e2
->key
.ipnode
.af_family
)
128 else if (e1
->key
.ipnode
.af_family
< e2
->key
.ipnode
.af_family
)
131 l1
= strlen(e1
->key
.ipnode
.name
);
132 l2
= strlen(e2
->key
.ipnode
.name
);
133 res
= strncasecmp(e1
->key
.ipnode
.name
, e2
->key
.ipnode
.name
,
135 return (_NSC_INT_KEY_CMP(res
, 0));
139 ipname_gethash(nss_XbyY_key_t
*key
, int htsize
) {
140 return (cis_gethash(key
->ipnode
.name
, htsize
));
144 ipname_getlogstr(char *name
, char *whoami
, size_t len
, nss_XbyY_args_t
*argp
) {
145 (void) snprintf(whoami
, len
, "%s [key=%s:af=%d:flags=%d]",
147 argp
->key
.ipnode
.name
,
148 argp
->key
.ipnode
.af_family
,
149 argp
->key
.ipnode
.flags
);