The library is now glued together from generic and OS-dependent parts

by the `mergedirs' script. Few more IP address manipulation functions
and some fixes.
This commit is contained in:
Martin Mares 1998-05-15 07:56:13 +00:00
parent 62aa008abd
commit 25697773b5
20 changed files with 152 additions and 30 deletions

View file

@ -2,32 +2,41 @@
# (c) 1998 Martin Mares <mj@ucw.cz> # (c) 1998 Martin Mares <mj@ucw.cz>
TOPDIR=$(shell pwd) TOPDIR=$(shell pwd)
OBJDIR=obj
CPPFLAGS=-I$(TOPDIR)/sysdep/linux -I$(TOPDIR) CPPFLAGS=-I$(TOPDIR)/sysdep/linux -I$(TOPDIR)
OPT=-O2 OPT=-O2
DEBUG=-g#gdb DEBUG=-g#gdb
CFLAGS=$(OPT) $(DEBUG) -Wall -W -Wstrict-prototypes -Wno-unused -Wno-parentheses CFLAGS=$(OPT) $(DEBUG) -Wall -W -Wstrict-prototypes -Wno-unused -Wno-parentheses
PROTOCOLS= PROTOCOLS=
DIRS=nest $(PROTOCOLS) lib sysdep/linux sysdep/unix LIBDIRS=sysdep/linux sysdep/unix lib
ARCHS=$(join $(addsuffix /,$(DIRS)),$(subst /,_,$(addsuffix .a,$(DIRS)))) STDDIRS=nest $(PROTOCOLS)
DIRS=$(STDDIRS) $(OBJDIR)/lib
PARTOBJS=$(join $(addsuffix /,$(STDDIRS)),$(subst /,_,$(addsuffix .o,$(STDDIRS))))
LIBS=$(OBJDIR)/lib/birdlib.a
export export
all: .dep all-dirs bird all: .dep all-dirs bird
all-dirs: all-dirs:
set -e ; for a in $(DIRS) ; do $(MAKE) -C $$a ; done set -e ; for a in $(DIRS) ; do $(MAKE) -C $$a all ; done
bird: $(ARCHS) bird: $(PARTOBJS) $(LIBS)
$(CC) $(LDFLAGS) -o $@ $^ $(CC) $(LDFLAGS) -o $@ $^
.dep: .dep:
$(MAKE) dep $(MAKE) dep
touch .dep
dep: dep:
mkdir -p $(OBJDIR)
tools/mergedirs $(OBJDIR) $(LIBDIRS)
# for a in $(STDDIRS) ; do mkdir -p $(OBJDIR)/$$a ; done
set -e ; for a in $(DIRS) ; do $(MAKE) -C $$a dep ; done set -e ; for a in $(DIRS) ; do $(MAKE) -C $$a dep ; done
touch .dep
clean: clean:
rm -rf obj
rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core -or -name .depend -or -name .#*` rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core -or -name .depend -or -name .#*`
rm -f bird .dep rm -f bird .dep

29
Rules
View file

@ -3,17 +3,32 @@
THISDIR=$(shell pwd) THISDIR=$(shell pwd)
RELDIR=$(subst $(TOPDIR)/,,$(THISDIR)) RELDIR=$(subst $(TOPDIR)/,,$(THISDIR))
ANAME=$(subst /,_,$(RELDIR)).a ONAME=$(subst /,_,$(RELDIR)).o
ifndef SRCS
SRCS=$(subst .o,.c,$(OBJS)) SRCS=$(subst .o,.c,$(OBJS))
endif
all: $(ANAME)
$(ANAME): $(OBJS)
rm -f $(ANAME)
ar rcs $(ANAME) $(OBJS)
ifdef OBJS ifdef OBJS
ifdef LIB
all: $(LIB)
$(LIB): $(OBJS)
rm -f $(LIB)
ar rcs $(LIB) $(OBJS)
ranlib $(LIB)
else
all: $(ONAME)
$(ONAME): $(OBJS)
$(LD) -r -o $(ONAME) $(OBJS)
endif
dep: $(SRCS) dep: $(SRCS)
rm -f .depend rm -f .depend
for a in $(SRCS) ; do gcc $(CPPFLAGS) -MM $$a >>.depend ; done for a in $(SRCS) ; do gcc $(CPPFLAGS) -MM $$a >>.depend ; done

View file

@ -1,9 +0,0 @@
OBJS=lists.o bitops.o resource.o xmalloc.o mempool.o slab.o md5.o
ifdef IPV6
OBJS += ipv6.o
else
OBJS += ipv4.o
endif
include $(TOPDIR)/Rules

19
lib/Modules Normal file
View file

@ -0,0 +1,19 @@
birdlib.h
bitops.c
bitops.h
ip.h
ipv4.c
ipv4.h
ipv6.c
ipv6.h
lists.c
lists.h
md5.c
md5.h
mempool.c
resource.c
resource.h
slab.c
socket.h
unaligned.h
xmalloc.c

View file

@ -21,8 +21,8 @@
/* Logging and dying */ /* Logging and dying */
void log(char *msg, ...); void log(char *msg, ...) __attribute__((format(printf,1,2)));
void die(char *msg, ...) NORET; void die(char *msg, ...) __attribute__((format(printf,1,2))) NORET;
#define L_DEBUG "\001" /* Debugging messages */ #define L_DEBUG "\001" /* Debugging messages */
#define L_INFO "\002" /* Informational messages */ #define L_INFO "\002" /* Informational messages */

View file

@ -35,4 +35,10 @@
#define SCOPE_SITE 2 #define SCOPE_SITE 2
#define SCOPE_UNIVERSE 3 #define SCOPE_UNIVERSE 3
/*
* Is it a valid network prefix?
*/
#define ip_is_prefix(a,l) (!ipa_nonzero(ipa_and(a, ipa_not(ipa_mkmask(l)))))
#endif #endif

View file

@ -6,6 +6,8 @@
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
#ifndef IPV6
#include "nest/bird.h" #include "nest/bird.h"
#include "lib/ip.h" #include "lib/ip.h"
@ -27,3 +29,5 @@ ipv4_classify(u32 a)
return IADDR_BROADCAST | SCOPE_LINK; return IADDR_BROADCAST | SCOPE_LINK;
return IADDR_INVALID; return IADDR_INVALID;
} }
#endif

View file

@ -25,7 +25,7 @@ typedef struct ipv4_addr {
} ip_addr; } ip_addr;
#define _I(x) (x).addr #define _I(x) (x).addr
#define _MI(x) ((struct ip_addr) { x }) #define _MI(x) ((struct ipv4_addr) { x })
#else #else
@ -36,6 +36,8 @@ typedef u32 ip_addr;
#endif #endif
#define BITS_PER_IP_ADDRESS 32
#define IPA_NONE (_MI(0)) #define IPA_NONE (_MI(0))
#define ipa_equal(x,y) (_I(x) == _I(y)) #define ipa_equal(x,y) (_I(x) == _I(y))
@ -50,8 +52,6 @@ typedef u32 ip_addr;
#define ipa_ntoh(x) x = _MI(ntohl(_I(x))) #define ipa_ntoh(x) x = _MI(ntohl(_I(x)))
#define ipa_classify(x) ipv4_classify(_I(x)) #define ipa_classify(x) ipv4_classify(_I(x))
unsigned ipv4_mklen(u32);
u32 ipv4_mkmask(unsigned);
int ipv4_classify(u32); int ipv4_classify(u32);
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */ /* FIXME: Is this hash function uniformly distributed over standard routing tables? */

View file

@ -6,7 +6,11 @@
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
#ifdef IPV6
#include "nest/bird.h" #include "nest/bird.h"
#include "lib/ip.h" #include "lib/ip.h"
#error "Ought to implement these." #error "Ought to implement these."
#endif

View file

@ -22,6 +22,8 @@ typedef struct ipv4_addr {
#define _I2(a) ((a).addr[2]) #define _I2(a) ((a).addr[2])
#define _I3(a) ((a).addr[3]) #define _I3(a) ((a).addr[3])
#define BITS_PER_IP_ADDRESS 128
#define IPA_NONE _MI(0,0,0,0) #define IPA_NONE _MI(0,0,0,0)
#define ipa_equal(x,y) (!memcmp(&(x),&(y),sizeof(ip_addr))) #define ipa_equal(x,y) (!memcmp(&(x),&(y),sizeof(ip_addr)))

View file

@ -9,3 +9,7 @@
#undef CONFIG_TOS #undef CONFIG_TOS
#undef CONFIG_MULTIPATH #undef CONFIG_MULTIPATH
#undef CONFIG_NETLINK #undef CONFIG_NETLINK
/*
Link: sysdep/linux
*/

View file

@ -9,3 +9,7 @@
#define CONFIG_TOS #define CONFIG_TOS
#define CONFIG_MULTIPATH #define CONFIG_MULTIPATH
#define CONFIG_NETLINK #define CONFIG_NETLINK
/*
Link: sysdep/linux
*/

View file

@ -11,3 +11,7 @@
#define CONFIG_TOS #define CONFIG_TOS
#define CONFIG_MULTIPATH #define CONFIG_MULTIPATH
#define CONFIG_NETLINK #define CONFIG_NETLINK
/*
Link: sysdep/linux
*/

View file

@ -1 +0,0 @@
include $(TOPDIR)/Rules

0
sysdep/linux/Modules Normal file
View file

View file

@ -1,3 +0,0 @@
OBJS=log.o
include $(TOPDIR)/Rules

3
sysdep/unix/Modules Normal file
View file

@ -0,0 +1,3 @@
log.c
main.c
timer.h

25
sysdep/unix/main.c Normal file
View file

@ -0,0 +1,25 @@
/*
* BIRD Internet Routing Daemon -- Unix Entry Point
*
* (c) 1998 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include <stdio.h>
#include "nest/bird.h"
#include "lib/lists.h"
#include "lib/resource.h"
#include "nest/route.h"
int
main(void)
{
log(L_INFO "Launching BIRD -1.-1-pre-omega...");
log_init_debug(NULL);
resource_init();
return 0;
}

36
tools/mergedirs Executable file
View file

@ -0,0 +1,36 @@
#!/bin/sh
if [ -z "$2" ] ; then
echo "Usage: mergedirs <obj-dir> <list-of-dirs>"
exit 1
fi
TOPDIR=`pwd`
OBJDIR=$1
LIBDIR=$OBJDIR/lib
shift
echo "Merging system-dependent modules"
MODULES=`for a in $@ ; do
sed <$a/Modules "s@\\(.*\\)@\\1 $a/\\1@"
done |
sort +0 -1 -u |
cut -d ' ' -f 2`
rm -rf $LIBDIR
mkdir -p $LIBDIR
for a in $MODULES ; do
echo $a
b=`basename $a`
ln -s $TOPDIR/$a $LIBDIR/$b
OBJ=`echo $b | sed '/\.c$/!d;s/\.c$/\.o/'`
if [ -n "$OBJ" ] ; then
OBJS="$OBJS $OBJ"
SRCS="$SRCS \\
\$(TOPDIR)/$a"
fi
done
cat >$LIBDIR/Makefile <<EOF
OBJS=$OBJS
SRCS=$SRCS
LIB=birdlib.a
include \$(TOPDIR)/Rules
EOF