summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mrouted/inet.c
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1995-06-13 18:05:16 +0000
committerwollman <wollman@FreeBSD.org>1995-06-13 18:05:16 +0000
commitd7ec2bee9b62915b2bfc4cbeffefb602d913f92d (patch)
tree251f664e3bb6640c0dc6968bd9a6ec402be8d14b /usr.sbin/mrouted/inet.c
parent20ad4f8359820cf12331c0335034438fc23ad604 (diff)
downloadFreeBSD-src-d7ec2bee9b62915b2bfc4cbeffefb602d913f92d.zip
FreeBSD-src-d7ec2bee9b62915b2bfc4cbeffefb602d913f92d.tar.gz
This is mrouted version 3.5, with the route-change notification hook from
mrouted-3.5n. This is being splatted onto the head rather than properly imported thanks to the ``delete trailing whitespace'' screw. This code is now actively working in an operational environment (the DARTNET) so I have some confidence that the basic functionality actually works. Obtained from: Bill Fenner, PARC, and ISI
Diffstat (limited to 'usr.sbin/mrouted/inet.c')
-rw-r--r--usr.sbin/mrouted/inet.c64
1 files changed, 40 insertions, 24 deletions
diff --git a/usr.sbin/mrouted/inet.c b/usr.sbin/mrouted/inet.c
index 5d7442b..b888bec 100644
--- a/usr.sbin/mrouted/inet.c
+++ b/usr.sbin/mrouted/inet.c
@@ -7,7 +7,7 @@
* Leland Stanford Junior University.
*
*
- * $Id: inet.c,v 1.4 1993/05/30 01:36:38 deering Exp $
+ * $Id: inet.c,v 3.5 1995/05/09 01:00:39 fenner Exp $
*/
@@ -17,9 +17,10 @@
/*
* Exported variables.
*/
-char s1[16]; /* buffers to hold the string representations */
-char s2[16]; /* of IP addresses, to be passed to inet_fmt() */
-char s3[16]; /* or inet_fmts(). */
+char s1[19]; /* buffers to hold the string representations */
+char s2[19]; /* of IP addresses, to be passed to inet_fmt() */
+char s3[19]; /* or inet_fmts(). */
+char s4[19];
/*
@@ -28,9 +29,9 @@ char s3[16]; /* or inet_fmts(). */
* {subnet,-1}.)
*/
int inet_valid_host(naddr)
- u_long naddr;
+ u_int32 naddr;
{
- register u_long addr;
+ register u_int32 addr;
addr = ntohl(naddr);
@@ -42,29 +43,38 @@ int inet_valid_host(naddr)
/*
* Verify that a given subnet number and mask pair are credible.
+ *
+ * With CIDR, almost any subnet and mask are credible. mrouted still
+ * can't handle aggregated class A's, so we still check that, but
+ * otherwise the only requirements are that the subnet address is
+ * within the [ABC] range and that the host bits of the subnet
+ * are all 0.
*/
int inet_valid_subnet(nsubnet, nmask)
- u_long nsubnet, nmask;
+ u_int32 nsubnet, nmask;
{
- register u_long subnet, mask;
+ register u_int32 subnet, mask;
subnet = ntohl(nsubnet);
mask = ntohl(nmask);
if ((subnet & mask) != subnet) return (FALSE);
+ if (subnet == 0 && mask == 0)
+ return (TRUE);
+
if (IN_CLASSA(subnet)) {
if (mask < 0xff000000 ||
- (subnet & 0xff000000) == 0 ||
(subnet & 0xff000000) == 0x7f000000) return (FALSE);
}
- else if (IN_CLASSB(subnet)) {
- if (mask < 0xffff0000) return (FALSE);
+ else if (IN_CLASSD(subnet) || IN_BADCLASS(subnet)) {
+ /* Above Class C address space */
+ return (FALSE);
}
- else if (IN_CLASSC(subnet)) {
- if (mask < 0xffffff00) return (FALSE);
+ else if (subnet & ~mask) {
+ /* Host bits are set in the subnet */
+ return (FALSE);
}
- else return (FALSE);
return (TRUE);
}
@@ -74,7 +84,7 @@ int inet_valid_subnet(nsubnet, nmask)
* Convert an IP address in u_long (network) format into a printable string.
*/
char *inet_fmt(addr, s)
- u_long addr;
+ u_int32 addr;
char *s;
{
register u_char *a;
@@ -87,36 +97,42 @@ char *inet_fmt(addr, s)
/*
* Convert an IP subnet number in u_long (network) format into a printable
- * string.
+ * string including the netmask as a number of bits.
*/
char *inet_fmts(addr, mask, s)
- u_long addr, mask;
+ u_int32 addr, mask;
char *s;
{
register u_char *a, *m;
+ int bits;
+ if ((addr == 0) && (mask == 0)) {
+ sprintf(s, "default");
+ return (s);
+ }
a = (u_char *)&addr;
m = (u_char *)&mask;
+ bits = 33 - ffs(ntohl(mask));
- if (m[3] != 0) sprintf(s, "%u.%u.%u.%u", a[0], a[1], a[2], a[3]);
- else if (m[2] != 0) sprintf(s, "%u.%u.%u", a[0], a[1], a[2]);
- else if (m[1] != 0) sprintf(s, "%u.%u", a[0], a[1]);
- else sprintf(s, "%u", a[0]);
+ if (m[3] != 0) sprintf(s, "%u.%u.%u.%u/%d", a[0], a[1], a[2], a[3],
+ bits);
+ else if (m[2] != 0) sprintf(s, "%u.%u.%u/%d", a[0], a[1], a[2], bits);
+ else if (m[1] != 0) sprintf(s, "%u.%u/%d", a[0], a[1], bits);
+ else sprintf(s, "%u/%d", a[0], bits);
return (s);
}
-
/*
* Convert the printable string representation of an IP address into the
* u_long (network) format. Return 0xffffffff on error. (To detect the
* legal address with that value, you must explicitly compare the string
* with "255.255.255.255".)
*/
-u_long inet_parse(s)
+u_int32 inet_parse(s)
char *s;
{
- u_long a;
+ u_int32 a = 0;
u_int a0, a1, a2, a3;
char c;
OpenPOWER on IntegriCloud