smbns_nicconfig.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <libintl.h>
#include <strings.h>
#include <unistd.h>
#include <synch.h>
#include <stropts.h>
#include <errno.h>
#include <pthread.h>
#include <netdb.h>
#include <resolv.h>
#include <sys/systeminfo.h>
#include <smbsrv/libsmbns.h>
static int smb_nic_get_list(struct if_list **);
static void smb_nic_clear_if_list(struct if_list *);
/* This is the list we will monitor */
/* Nameserver information */
static struct __res_state smb_res;
void
smb_resolver_init(void)
{
int ret;
(void) pthread_mutex_lock(&smb_ns_mutex);
(void) pthread_mutex_unlock(&smb_ns_mutex);
if (ret < 0) {
}
}
void
smb_resolver_close(void)
{
(void) pthread_mutex_lock(&smb_ns_mutex);
(void) pthread_mutex_unlock(&smb_ns_mutex);
}
int
{
int i, cnt;
return (0);
(void) pthread_mutex_lock(&smb_ns_mutex);
for (i = 0; i < cnt; i++) {
if (i >= sz)
break;
}
(void) pthread_mutex_unlock(&smb_ns_mutex);
return (i);
}
smb_get_next_resid(void)
{
(void) pthread_mutex_lock(&smb_ns_mutex);
(void) pthread_mutex_unlock(&smb_ns_mutex);
return (id);
}
/*
* The common NIC library will provide functions to obtain information
* on all interfaces. Information will include IP addresses, netmasks
* and broadcast address, as well as network statistic details.
*/
/*
* Return IP string address associated with interface argument.
* If an error occurs, -1 will be returned.
* A return value of 1 indicates an unconfigured IP address
*/
static int
{
struct sockaddr_in *sa;
int sfd;
if (sfd < 0) {
return (-1);
}
return (-1);
}
/* Test length of allocated memory to avoid buffer overflow */
"allocation\n");
return (-1);
}
/* Check for unconfigured interface */
return (1);
}
return (0);
}
/*
* Return IP address associated with interface argument. If an error occurs,
* -1 will be returned. A return value of 1 indicates an unconfigured IP
* address
*/
int
{
struct sockaddr_in *sa;
int sfd;
if (sfd < 0) {
return (-1);
}
return (-1);
}
return (0);
}
/*
* Return broadcast address associated with interface argument.If an error
* occurs, -1 will be returned. A return value of 1 indicates an unconfigured
* broadcast address
*/
int
{
struct sockaddr_in *sa;
int sfd;
if (sfd < 0) {
"socket open failed\n");
return (-1);
}
"get broadcast address failed\n");
return (-1);
}
return (0);
}
/*
* Return netmask address associated with interface argument. If error occurs,
* -1 will be returned. A return value of 1 indicates an unconfigured netmask
* address
*/
int
{
struct sockaddr_in *sa;
int sfd;
if (sfd < 0) {
"socket open failed\n");
return (-1);
}
"get netmask address failed\n");
return (-1);
}
return (0);
}
/*
* Fill ip_alias with IP addresses if any
* If it returns 0, there are no associated aliases with the interface.
* If it returns -1, there was an error
* If it returns 1, there are associated IP aliases with the interface.
*/
int
{
int result = 0;
/* If the interface is a logical interface, return immediately */
"invalid physical interface");
return (ret);
}
for (i = 0; i < numnics; i++) {
/*
* Compare passed interface name to all other interface names.
* If it matches in the form of :1, it is an associated alias
* Example bge1:1's ip address is an ip alias of bge1
*/
if (result == -1)
return (result);
sizeof (struct ip_alias));
"_IP_aliases: out of memory");
(void) smb_nic_clear_name_list(names,
numnics);
return (-1);
}
ret = 1;
}
}
return (ret);
}
/*
* Return number of plumbed interfaces. Loopback interface is ignored
*/
int
smb_nic_get_number(void)
{
if (sfd < 0) {
"socket open failed");
return (-1);
}
lifn.lifn_flags = 0;
"unable to determine number");
return (-1);
}
return (numifs);
}
/*
* Given an interface name, return the name of the group it belongs to.
*/
int
{
int sfd;
int save_errno;
if (sfd < 0) {
return (-1);
}
sizeof (lifr.lifr_groupname));
sizeof (lifr.lifr_groupname));
}
} else {
save_errno = errno;
errno = save_errno;
return (-1);
}
}
return (0);
}
/*
* Read the /etc/defaultrouter file for the gateway address. If an error occurs,
* -1 will be returned.
*/
int
{
return (-1);
} else {
/* Test length of allocated memory to avoid buffer overflow */
"insufficient memory allocation\n");
return (-1);
}
}
return (0);
}
/*
* Build the list of interface names, both physical and logical.
* A pointer to a pointer to a char will be filled with the info
*/
int
smb_nic_build_if_name(char ***if_names)
{
int num_ifs, i;
/* Get the interfaces */
/* Build the list of names */
return (-1);
}
}
(void) smb_nic_clear_if_list(iflist);
return (num_ifs);
}
/*
* Get number of physical interfaces
*/
int
smb_nic_get_num_physical(void)
{
int phys_ifs = 0;
int i, result = 0;
/* Get list of interface names */
if (result == -1) {
return (-1);
}
for (i = 0; i < result; i++) {
/* It's a physical interface */
phys_ifs++;
}
}
return (phys_ifs);
}
/*
* Get number of logical interfaces
*/
int
smb_nic_get_num_logical(void)
{
int log_ifs = 0;
int i, result = 0;
/* Get list of interface names */
if (result == -1) {
return (-1);
}
for (i = 0; i < result; i++) {
/* It's a logical interface */
log_ifs++;
}
}
return (log_ifs);
}
/*
* Get number of aliases associated with an interface
*/
int
smb_nic_get_num_aliases(char *interface)
{
int aliases = 0;
int i, result = 0;
return (-1);
}
/* Get list of interface names */
if (result == -1) {
return (-1);
}
for (i = 0; i < result; i++) {
/* It's an alias */
aliases++;
}
}
if (aliases == 0)
return (1); /* Minimum of 1 for NULL assignment */
else
return (aliases);
}
/*
* Get the list of currently plumbed interface names. The loopback(lo0)
* port is ignored
*/
static int
{
int cnt = 0;
int n, s;
char *buf;
int numifs = 0;
unsigned int bufsize = 0;
if (s < 0) {
return (-1);
}
return (-1);
}
(void) close(s);
return (-1);
}
(void) close(s);
return (-1);
}
/* Get the flags so that we can skip the loopback interface */
(void) close(s);
return (-1);
}
continue;
continue;
(void) close(s);
return (-1);
}
} else {
;
}
cnt++;
}
(void) close(s);
return (cnt);
}
/*
* This will mimick the workings of ifconfig -a command. A net_cfg
* pointer will be passed, and all information will be assigned
* within this function. Memory will be assigned in this function
* also so the user doesn't have to worry about it. Freeing memory
* will be handled in a different function - smb_nic_clear_memory
*/
int
{
int num_aliases = 0;
int i = 0;
int j = 1;
int k = 0;
char excludestr[MAX_EXCLUDE_LIST_LEN];
int nexclude;
char *winsexclude;
*number = 0;
return (-1);
}
excludestr[0] = '\0';
if (winsexclude != NULL)
for (i = 0; i < numnics; i++) {
/* Will not provide info on logical interfaces */
if (num_aliases == -1) {
return (-1);
}
(sizeof (char) * IP_ABITS) * num_aliases);
return (-1);
}
return (-1);
}
nexclude))
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
/*
* If an interface has no associated alias, the alias
* field will be set to NULL
*/
if (res == -1) {
return (-1);
}
if (res == 0) {
} else { /* There will be aliases */
j++;
}
}
k++;
j = 1;
(*nc)++; /* increment pointer */
}
} /* end for */
*number = k;
return (0);
}
/*
* Return a space separated list of interface names depending on specified
* flags. Either flags argument can be set to 0 if the caller chooses.
* Returns NULL if no interfaces match the passed flags
* flags_on: flags which must be on in each interface returned
* flags_off : flags which must be off in each interface returned
*/
char *
{
char *ifnames;
if (sfd == -1)
return (NULL);
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
for (i = 0; i < numifs; i++) {
continue;
}
}
}
return (ifnames);
}
/*
* Function to determine if passed address is of form a.b.c.d.
*/
int
smb_nic_validate_ip_address(char *IP)
{
" of the form a.b.c.d");
return (addr);
}
else
return (0);
}
/*
* Get flags associated with if
* -1 means there was an error retrieving the data
* 0 success
*/
int
{
int sfd;
if (sfd < 0) {
return (-1);
}
return (-1);
}
return (0);
}
/*
* The following list is taken from if.h. The function takes the
* given interface name, and the passed flag(s), and returns true if
* the flag is associated with the interface, and false if not.
*
* IFF_UP interface is up
* IFF_BROADCAST broadcast address valid
* IFF_LOOPBACK is a loopback net
* IFF_POINTOPOINT interface is point-to-point link
* IFF_RUNNING resources allocated
* IFF_MULTICAST supports multicast
* IFF_MULTI_BCAST multicast using broadcast address
* IFF_UNNUMBERED non-unique address
* IFF_DHCPRUNNING DHCP controls this interface
* IFF_PRIVATE do not advertise
* IFF_DEPRECATED interface address deprecated
* IFF_ANYCAST Anycast address
* IFF_IPV4 IPv4 interface
* IFF_IPV6 IPv6 interface
* IFF_NOFAILOVER Don't failover on NIC failure
* IFF_FAILED NIC has failed
* IFF_STANDBY Standby NIC to be used on failures
* IFF_OFFLINE NIC has been offlined
* -1 means there was an error retrieving the data
* 0 indicates false - the flag isn't associated
* 1 indicates true - the flag is associated
*/
int
{
int sfd;
if (sfd < 0) {
return (-1);
}
return (-1);
}
return (1); /* associated */
} else {
return (0); /* not associated */
}
}
/*
* Free allocated memory for net_cfg structures. Takes number of allocated
* structures as argument also
*/
int
{
int i, j = 0;
return (-1);
for (i = 0; i < amount; i++) {
j++;
}
j = 0;
}
return (0);
}
int
{
niclist->net_cfg_cnt));
}
/*
* Free allocated memory for names lists. Takes number of allocated
* pointers as argument also
*/
int
{
int i;
for (i = 0; i < amount; i++) {
}
return (0);
}
/* Free allocated memory for names lists. */
static void
{
return;
}
}
/* Free allocated memory for alias lists. */
int
{
}
return (0);
}
/*
* smb_nic_lock
*
* Lock the nic table
*/
void
smb_nic_lock(void)
{
(void) pthread_mutex_lock(&smb_nic_mutex);
}
/*
* smb_nic_unlock
*
* Unlock the nic table.
*
* This function MUST be called after lock
*/
void
smb_nic_unlock(void)
{
(void) pthread_mutex_unlock(&smb_nic_mutex);
}
int
{
smb_nic_lock();
smb_nic_list.net_cfg_cnt = 0;
return (0);
}
/*
* Initialize interface list.
*/
void
smb_nic_build_info(void)
{
smb_nic_lock();
if (smb_nic_list.net_cfg_list) {
(void) smb_nic_free_niclist(&smb_nic_list);
}
smb_nic_list.net_cfg_cnt = 0;
if (smb_nic_list.net_cfg_cnt == 0) {
"smb server may not function properly");
}
}
/*
* Get number of interfaces.
*/
int
smb_nic_get_num(void)
{
int sz;
smb_nic_lock();
return (sz);
}
/*
* Get if by index
* Returns: NULL if not found.
*/
{
return (cfg);
smb_nic_lock();
return (NULL);
}
return (cfg);
}
/*
* Get if by subnet
* Returns: NULL if not found.
*/
{
int i;
return (cfg);
smb_nic_lock();
for (i = 0; i < smb_nic_list.net_cfg_cnt; i++) {
return (cfg);
}
}
return (NULL);
}
/*
* Get if by ip.
* Returns: NULL if not found.
*/
{
int i;
return (cfg);
smb_nic_lock();
for (i = 0; i < smb_nic_list.net_cfg_cnt; i++) {
return (cfg);
}
}
return (NULL);
}