1*2830Sdjl /*
2*2830Sdjl * CDDL HEADER START
3*2830Sdjl *
4*2830Sdjl * The contents of this file are subject to the terms of the
5*2830Sdjl * Common Development and Distribution License (the "License").
6*2830Sdjl * You may not use this file except in compliance with the License.
7*2830Sdjl *
8*2830Sdjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2830Sdjl * or http://www.opensolaris.org/os/licensing.
10*2830Sdjl * See the License for the specific language governing permissions
11*2830Sdjl * and limitations under the License.
12*2830Sdjl *
13*2830Sdjl * When distributing Covered Code, include this CDDL HEADER in each
14*2830Sdjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2830Sdjl * If applicable, add the following below this CDDL HEADER, with the
16*2830Sdjl * fields enclosed by brackets "[]" replaced with your own identifying
17*2830Sdjl * information: Portions Copyright [yyyy] [name of copyright owner]
18*2830Sdjl *
19*2830Sdjl * CDDL HEADER END
20*2830Sdjl */
21*2830Sdjl /*
22*2830Sdjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*2830Sdjl * Use is subject to license terms.
24*2830Sdjl */
25*2830Sdjl
26*2830Sdjl #pragma ident "%Z%%M% %I% %E% SMI"
27*2830Sdjl
28*2830Sdjl /*
29*2830Sdjl * Routines to handle ether_*to* calls in nscd
30*2830Sdjl */
31*2830Sdjl
32*2830Sdjl #include <stdlib.h>
33*2830Sdjl #include <net/if.h>
34*2830Sdjl #include <netinet/in.h>
35*2830Sdjl #include <netinet/if_ether.h>
36*2830Sdjl #include <string.h>
37*2830Sdjl #include "cache.h"
38*2830Sdjl
39*2830Sdjl #define host_db ctx->nsc_db[0]
40*2830Sdjl #define addr_db ctx->nsc_db[1]
41*2830Sdjl
42*2830Sdjl #define NSC_NAME_ETHERS_HOSTTON "ether_hostton"
43*2830Sdjl #define NSC_NAME_ETHERS_NTOHOST "ether_ntohost"
44*2830Sdjl
45*2830Sdjl static void ether_getlogstr(char *, char *, size_t, nss_XbyY_args_t *);
46*2830Sdjl static int ether_compar(const void *, const void *);
47*2830Sdjl static uint_t ether_gethash(nss_XbyY_key_t *, int);
48*2830Sdjl
49*2830Sdjl void
ether_init_ctx(nsc_ctx_t * ctx)50*2830Sdjl ether_init_ctx(nsc_ctx_t *ctx) {
51*2830Sdjl ctx->dbname = NSS_DBNAM_ETHERS;
52*2830Sdjl ctx->file_name = "/etc/ethers";
53*2830Sdjl ctx->db_count = 2;
54*2830Sdjl host_db = make_cache(nsc_key_cis,
55*2830Sdjl NSS_DBOP_ETHERS_HOSTTON,
56*2830Sdjl NSC_NAME_ETHERS_HOSTTON,
57*2830Sdjl NULL, NULL, NULL, nsc_ht_default, -1);
58*2830Sdjl
59*2830Sdjl addr_db = make_cache(nsc_key_other,
60*2830Sdjl NSS_DBOP_ETHERS_NTOHOST,
61*2830Sdjl NSC_NAME_ETHERS_NTOHOST,
62*2830Sdjl ether_compar,
63*2830Sdjl ether_getlogstr,
64*2830Sdjl ether_gethash, nsc_ht_default, -1);
65*2830Sdjl }
66*2830Sdjl
67*2830Sdjl static int
ether_compar(const void * n1,const void * n2)68*2830Sdjl ether_compar(const void *n1, const void *n2) {
69*2830Sdjl nsc_entry_t *e1, *e2;
70*2830Sdjl int res;
71*2830Sdjl
72*2830Sdjl e1 = (nsc_entry_t *)n1;
73*2830Sdjl e2 = (nsc_entry_t *)n2;
74*2830Sdjl if (ether_cmp(e1->key.ether, e2->key.ether) != 0) {
75*2830Sdjl res = memcmp(e1->key.ether, e2->key.ether,
76*2830Sdjl sizeof (struct ether_addr));
77*2830Sdjl return (_NSC_INT_KEY_CMP(res, 0));
78*2830Sdjl }
79*2830Sdjl return (0);
80*2830Sdjl }
81*2830Sdjl
82*2830Sdjl static uint_t
ether_gethash(nss_XbyY_key_t * key,int htsize)83*2830Sdjl ether_gethash(nss_XbyY_key_t *key, int htsize) {
84*2830Sdjl return (db_gethash(key->ether, sizeof (struct ether_addr),
85*2830Sdjl htsize));
86*2830Sdjl }
87*2830Sdjl
88*2830Sdjl static void
ether_getlogstr(char * name,char * whoami,size_t len,nss_XbyY_args_t * argp)89*2830Sdjl ether_getlogstr(char *name, char *whoami, size_t len, nss_XbyY_args_t *argp) {
90*2830Sdjl struct ether_addr *e;
91*2830Sdjl e = (struct ether_addr *)argp->key.ether;
92*2830Sdjl (void) snprintf(whoami, len, "%s [key=%x:%x:%x:%x:%x:%x]",
93*2830Sdjl name,
94*2830Sdjl e->ether_addr_octet[0], e->ether_addr_octet[1],
95*2830Sdjl e->ether_addr_octet[2], e->ether_addr_octet[3],
96*2830Sdjl e->ether_addr_octet[4], e->ether_addr_octet[5]);
97*2830Sdjl }
98