cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The contents of this file are subject to the terms of the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Common Development and Distribution License (the "License").
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You may not use this file except in compliance with the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * or http://www.opensolaris.org/os/licensing.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * See the License for the specific language governing permissions
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * and limitations under the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When distributing Covered Code, include this CDDL HEADER in each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * If applicable, add the following below this CDDL HEADER, with the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * fields enclosed by brackets "[]" replaced with your own identifying
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * information: Portions Copyright [yyyy] [name of copyright owner]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER END
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Use is subject to license terms.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#pragma ident "%Z%%M% %I% %E% SMI"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Routines to handle ether_*to* calls in nscd
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <stdlib.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <net/if.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <netinet/in.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <netinet/if_ether.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <string.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "cache.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define host_db ctx->nsc_db[0]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define addr_db ctx->nsc_db[1]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSC_NAME_ETHERS_HOSTTON "ether_hostton"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSC_NAME_ETHERS_NTOHOST "ether_ntohost"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void ether_getlogstr(char *, char *, size_t, nss_XbyY_args_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic int ether_compar(const void *, const void *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic uint_t ether_gethash(nss_XbyY_key_t *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlvoid
cb5caa98562cf06753163f558cbcfe30b8f4673adjlether_init_ctx(nsc_ctx_t *ctx) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->dbname = NSS_DBNAM_ETHERS;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->file_name = "/etc/ethers";
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ctx->db_count = 2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl host_db = make_cache(nsc_key_cis,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSS_DBOP_ETHERS_HOSTTON,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSC_NAME_ETHERS_HOSTTON,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NULL, NULL, NULL, nsc_ht_default, -1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl addr_db = make_cache(nsc_key_other,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSS_DBOP_ETHERS_NTOHOST,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSC_NAME_ETHERS_NTOHOST,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ether_compar,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ether_getlogstr,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ether_gethash, nsc_ht_default, -1);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic int
cb5caa98562cf06753163f558cbcfe30b8f4673adjlether_compar(const void *n1, const void *n2) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_t *e1, *e2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int res;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e1 = (nsc_entry_t *)n1;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e2 = (nsc_entry_t *)n2;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (ether_cmp(e1->key.ether, e2->key.ether) != 0) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl res = memcmp(e1->key.ether, e2->key.ether,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl sizeof (struct ether_addr));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (_NSC_INT_KEY_CMP(res, 0));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (0);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic uint_t
cb5caa98562cf06753163f558cbcfe30b8f4673adjlether_gethash(nss_XbyY_key_t *key, int htsize) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl return (db_gethash(key->ether, sizeof (struct ether_addr),
cb5caa98562cf06753163f558cbcfe30b8f4673adjl htsize));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void
cb5caa98562cf06753163f558cbcfe30b8f4673adjlether_getlogstr(char *name, char *whoami, size_t len, nss_XbyY_args_t *argp) {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl struct ether_addr *e;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e = (struct ether_addr *)argp->key.ether;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) snprintf(whoami, len, "%s [key=%x:%x:%x:%x:%x:%x]",
cb5caa98562cf06753163f558cbcfe30b8f4673adjl name,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e->ether_addr_octet[0], e->ether_addr_octet[1],
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e->ether_addr_octet[2], e->ether_addr_octet[3],
cb5caa98562cf06753163f558cbcfe30b8f4673adjl e->ether_addr_octet[4], e->ether_addr_octet[5]);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}