summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/interface.c124
1 files changed, 69 insertions, 55 deletions
diff --git a/source3/lib/interface.c b/source3/lib/interface.c
index c187583923..5982d82e47 100644
--- a/source3/lib/interface.c
+++ b/source3/lib/interface.c
@@ -1,18 +1,18 @@
-/*
+/*
Unix SMB/CIFS implementation.
multiple interface handling
Copyright (C) Andrew Tridgell 1992-1998
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -32,8 +32,9 @@ static struct interface *local_interfaces;
#define MKNETADDR(_IP, _NM) (_IP & _NM)
/****************************************************************************
-Try and find an interface that matches an ip. If we cannot, return NULL
- **************************************************************************/
+ Try and find an interface that matches an ip. If we cannot, return NULL.
+**************************************************************************/
+
static struct interface *iface_find(struct in_addr ip, BOOL CheckMask)
{
struct interface *i;
@@ -47,10 +48,10 @@ static struct interface *iface_find(struct in_addr ip, BOOL CheckMask)
return NULL;
}
-
/****************************************************************************
-add an interface to the linked list of interfaces
+ Add an interface to the linked list of interfaces.
****************************************************************************/
+
static void add_interface(struct in_addr ip, struct in_addr nmask)
{
struct interface *iface;
@@ -61,14 +62,15 @@ static void add_interface(struct in_addr ip, struct in_addr nmask)
#if !defined(__s390__)
if (ip_equal(nmask, allones_ip)) {
- DEBUG(3,("not adding non-broadcast interface %s\n",inet_ntoa(ip)));
+ DEBUG(3,("not adding non-broadcast interface %s\n",
+ inet_ntoa(ip)));
return;
}
#endif
iface = SMB_MALLOC_P(struct interface);
if (!iface) return;
-
+
ZERO_STRUCTPN(iface);
iface->ip = ip;
@@ -79,22 +81,21 @@ static void add_interface(struct in_addr ip, struct in_addr nmask)
DEBUG(2,("added interface ip=%s ",inet_ntoa(iface->ip)));
DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast)));
- DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask)));
+ DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask)));
}
-
-
/****************************************************************************
-interpret a single element from a interfaces= config line
+ Interpret a single element from a interfaces= config line.
-This handles the following different forms:
+ This handles the following different forms:
-1) wildcard interface name
-2) DNS name
-3) IP/masklen
-4) ip/mask
-5) bcast/mask
+ 1) wildcard interface name
+ 2) DNS name
+ 3) IP/masklen
+ 4) ip/mask
+ 5) bcast/mask
****************************************************************************/
+
static void interpret_interface(char *token)
{
struct in_addr ip, nmask;
@@ -119,11 +120,11 @@ static void interpret_interface(char *token)
if (!p) {
ip = *interpret_addr2(token);
for (i=0;i<total_probed;i++) {
- if (ip.s_addr == probed_ifaces[i].iface_addr.ip.s_addr &&
- !ip_equal(allones_ip,
+ if (ip.s_addr == probed_ifaces[i].iface_addr.ip.s_addr
+ && !ip_equal(allones_ip,
probed_ifaces[i].iface_netmask.netmask)) {
add_interface(probed_ifaces[i].iface_addr.ip,
- probed_ifaces[i].iface_netmask.netmask);
+ probed_ifaces[i].iface_netmask.netmask);
return;
}
}
@@ -146,22 +147,25 @@ static void interpret_interface(char *token)
if (ip.s_addr == MKBCADDR(ip.s_addr, nmask.s_addr) ||
ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) {
for (i=0;i<total_probed;i++) {
- if (same_net(ip, probed_ifaces[i].iface_addr.ip, nmask)) {
- add_interface(probed_ifaces[i].iface_addr.ip, nmask);
+ if (same_net(ip, probed_ifaces[i].iface_addr.ip,
+ nmask)) {
+ add_interface(probed_ifaces[i].iface_addr.ip,
+ nmask);
return;
}
}
- DEBUG(2,("Can't determine ip for broadcast address %s\n", token));
+ DEBUG(2,("Can't determine ip for broadcast address %s\n",
+ token));
return;
}
add_interface(ip, nmask);
}
-
/****************************************************************************
-load the list of network interfaces
+ Load the list of network interfaces.
****************************************************************************/
+
void load_interfaces(void)
{
const char **ptr;
@@ -187,28 +191,32 @@ void load_interfaces(void)
total_probed = get_interfaces(ifaces, MAX_INTERFACES);
if (total_probed > 0) {
- probed_ifaces = (struct iface_struct *)memdup(ifaces, sizeof(ifaces[0])*total_probed);
+ probed_ifaces = (struct iface_struct *)memdup(ifaces,
+ sizeof(ifaces[0])*total_probed);
if (!probed_ifaces) {
DEBUG(0,("ERROR: memdup failed\n"));
exit(1);
}
}
- /* if we don't have a interfaces line then use all broadcast capable
+ /* if we don't have a interfaces line then use all broadcast capable
interfaces except loopback */
if (!ptr || !*ptr || !**ptr) {
if (total_probed <= 0) {
- DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n"));
+ DEBUG(0,("ERROR: Could not determine network "
+ "interfaces, you must use a interfaces config line\n"));
exit(1);
}
for (i=0;i<total_probed;i++) {
if (
#if !defined(__s390__)
- probed_ifaces[i].iface_netmask.netmask.s_addr != allones_ip.s_addr &&
+ probed_ifaces[i].iface_netmask.netmask.s_addr !=
+ allones_ip.s_addr &&
#endif
- probed_ifaces[i].iface_addr.ip.s_addr != loopback_ip.s_addr) {
+ probed_ifaces[i].iface_addr.ip.s_addr !=
+ loopback_ip.s_addr) {
add_interface(probed_ifaces[i].iface_addr.ip,
- probed_ifaces[i].iface_netmask.netmask);
+ probed_ifaces[i].iface_netmask.netmask);
}
}
return;
@@ -244,8 +252,9 @@ void gfree_interfaces(void)
}
/****************************************************************************
-return True if the list of probed interfaces has changed
+ Return True if the list of probed interfaces has changed.
****************************************************************************/
+
BOOL interfaces_changed(void)
{
int n;
@@ -257,14 +266,14 @@ BOOL interfaces_changed(void)
memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n))) {
return True;
}
-
+
return False;
}
-
/****************************************************************************
- check if an IP is one of mine
- **************************************************************************/
+ Check if an IP is one of mine.
+**************************************************************************/
+
BOOL ismyip(struct in_addr ip)
{
struct interface *i;
@@ -274,13 +283,14 @@ BOOL ismyip(struct in_addr ip)
}
/****************************************************************************
- check if a packet is from a local (known) net
- **************************************************************************/
+ Check if a packet is from a local (known) net.
+**************************************************************************/
+
BOOL is_local_net(struct in_addr from)
{
struct interface *i;
for (i=local_interfaces;i;i=i->next) {
- if((from.s_addr & i->nmask.s_addr) ==
+ if((from.s_addr & i->nmask.s_addr) ==
(i->ip.s_addr & i->nmask.s_addr))
return True;
}
@@ -288,8 +298,9 @@ BOOL is_local_net(struct in_addr from)
}
/****************************************************************************
- how many interfaces do we have
- **************************************************************************/
+ How many interfaces do we have
+**************************************************************************/
+
int iface_count(void)
{
int ret = 0;
@@ -301,12 +312,13 @@ int iface_count(void)
}
/****************************************************************************
- return the Nth interface
- **************************************************************************/
+ Return the Nth interface.
+**************************************************************************/
+
struct interface *get_interface(int n)
-{
+{
struct interface *i;
-
+
for (i=local_interfaces;i && n;i=i->next)
n--;
@@ -315,12 +327,13 @@ struct interface *get_interface(int n)
}
/****************************************************************************
- return IP of the Nth interface
- **************************************************************************/
+ Return IP of the Nth interface.
+**************************************************************************/
+
struct in_addr *iface_n_ip(int n)
{
struct interface *i;
-
+
for (i=local_interfaces;i && n;i=i->next)
n--;
@@ -329,12 +342,13 @@ struct in_addr *iface_n_ip(int n)
}
/****************************************************************************
- return bcast of the Nth interface
- **************************************************************************/
+ Return bcast of the Nth interface.
+**************************************************************************/
+
struct in_addr *iface_n_bcast(int n)
{
struct interface *i;
-
+
for (i=local_interfaces;i && n;i=i->next)
n--;
@@ -342,7 +356,6 @@ struct in_addr *iface_n_bcast(int n)
return NULL;
}
-
/* these 3 functions return the ip/bcast/nmask for the interface
most appropriate for the given ip address. If they can't find
an appropriate interface they return the requested field of the
@@ -357,6 +370,7 @@ struct in_addr *iface_ip(struct in_addr ip)
/*
return True if a IP is directly reachable on one of our interfaces
*/
+
BOOL iface_local(struct in_addr ip)
{
return iface_find(ip, True) ? True : False;