/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* All routines necessary to deal the "netmasks" database. The sources
* contain mappings between 32 bit Internet addresses and corresponding
* 32 bit Internet address masks. The addresses are in dotted internet
* address notation.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <nss_dbdefs.h>
int str2addr(const char *, int, void *, char *, int);
static DEFINE_NSS_DB_ROOT(db_root);
void
{
p->name = NSS_DBNAM_NETMASKS;
}
/*
* Print a network number such as 129.144 as well as an IP address.
* Assumes network byte order for both IP addresses and network numbers
* (Network numbers are normally passed around in host byte order).
* to be MT safe, use a passed in buffer like otherget*_r APIs.
*/
static char *
{
return (NULL);
/* Omit leading zeros */
if (up[0]) {
} else if (up[1]) {
} else if (up[2]) {
} else {
}
return (result);
}
/*
* Given a 32 bit key look it up in the netmasks database
* based on the "netmasks" policy in /etc/nsswitch.conf.
* If the key is a network number with the trailing zero's removed
* (e.g. "192.9.200") this routine can't use inet_ntoa to convert
* the address to the string key.
* Returns zero if successful, non-zero otherwise.
*/
static int
{
/*
* let the backend do the allocation to store stuff for parsing.
* To simplify things, we put the dotted internet address form of
* the network address in the 'name' field as a filter to speed
* up the lookup.
*/
return (NSS_NOTFOUND);
(void) NSS_XbyY_FINI(&arg);
}
/*
* Given a 32 bit internet network number, it finds the corresponding netmask
* address based on the "netmasks" policy in /etc/nsswitch.conf.
* Returns zero if successful, non-zero otherwise.
* Check both for the (masked) network number and the shifted network
* number (e.g., both "10.0.0.0" and "10").
* Assumes that the caller passes in an unshifted number (or an IP address).
*/
int
{
uint32_t i;
/*
* Try looking for the network number both with and without
* the trailing zeros.
*/
if ((i & IN_CLASSA_NET) == 0) {
/* Assume already a right-shifted network number */
if ((i & IN_CLASSB_NET) != 0) {
} else if ((i & IN_CLASSC_NET) != 0) {
} else {
}
} else if (IN_CLASSA(i)) {
} else if (IN_CLASSB(i)) {
} else {
}
return (0);
}
return (0);
}
return (-1);
}
/*
* Find the netmask used for an IP address.
* Returns zero if successful, non-zero otherwise.
*
* Support Variable Length Subnetmasks by looking for the longest
* matching subnetmask in the database.
* Start by looking for a match for the full IP address and
* mask off one rightmost bit after another until we find a match.
* Note that for a match the found netmask must match what was used
* for the lookup masking.
* As a fallback for compatibility finally lookup the network
* number with and without the trailing zeros.
* In order to suppress redundant lookups in the name service
* we keep the previous lookup key and compare against it before
* doing the lookup.
*/
int
{
}
}
return (0);
}
/*
* Non-VLSM fallback.
* Try looking for the network number with and without the trailing
* zeros.
*/
}
/*
* Parse netmasks entry into its components. The network address is placed
* in buffer for use by check_addr for 'files' backend, to match the network
* address. The network address is placed in the buffer as a network order
* internet address, if buffer is non null. The network order form of the mask
* itself is placed in 'ent'.
*/
int
{
int retval;
int i;
p = instr;
p++;
if (buffer) { /* for 'files' backend verification */
i++;
tmp[i] = '\0';
/* Addr will always be an ipv4 address (32bits) */
return (NSS_STR_PARSE_PARSE);
else {
sizeof (struct in_addr));
}
} else
return (NSS_STR_PARSE_ERANGE);
}
p++;
if (mask) {
i++;
if (p <= limit) {
if ((i + 1) > NSS_LINELEN_NETMASKS)
return (NSS_STR_PARSE_ERANGE);
tmp[i] = '\0';
/* Addr will always be an ipv4 address (32bits) */
else {
}
}
}
return (retval);
}