Skip to content

Commit

Permalink
Initial work on the Longest Prefix Match (LPM) library.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmind committed May 24, 2016
0 parents commit fabdf67
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 0 deletions.
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*-
* Copyright (c) 2016 Mindaugas Rasiukevicius <rmind at noxt eu>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
12 changes: 12 additions & 0 deletions pkg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PROJ= lpm

all: rpm

rpm:
mkdir -p SOURCES && tar czpvf SOURCES/lib$(PROJ).tar.gz ../src
rpmbuild -ba -v --define "_topdir ${PWD}" SPECS/lib$(PROJ).spec

clean:
rm -rf BUILD BUILDROOT RPMS SOURCES SRPMS

.PHONY: all rpm clean
34 changes: 34 additions & 0 deletions pkg/SPECS/liblpm.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Name: liblpm
Version: 0.1
Release: 1%{?dist}
Summary: Longest Prefix Match (LPM) library
Group: System Environment/Libraries
License: BSD
URL: https://github.com/rmind/liblpm
Source0: liblpm.tar.gz

BuildRequires: make
BuildRequires: libtool

%description
Longest Prefix Match (LPM) library supporting IPv4 and IPv6.

%prep
%setup -q -n src

%build
make %{?_smp_mflags} LIBDIR=%{_libdir}

%install
make install \
DESTDIR=%{buildroot} \
LIBDIR=%{_libdir} \
INCDIR=%{_includedir} \
MANDIR=%{_mandir}

%files
%{_libdir}/*
%{_includedir}/*
#%{_mandir}/*

%changelog
55 changes: 55 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# This file is in the Public Domain.
#

CFLAGS= -std=gnu99 -O2 -flto -g -W -Wextra -Werror -D_BSD_SOURCE
CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
CFLAGS+= -Wshadow -Wcast-qual -Wwrite-strings

ifeq ($(MAKECMDGOALS),tests)
DEBUG= 1
endif

ifeq ($(DEBUG),1)
CFLAGS+= -O0 -DDEBUG -fno-omit-frame-pointer
else
CFLAGS+= -DNDEBUG
LDFLAGS= -flto
endif

LIB= liblpm
INCS= lpm.h

OBJS= lpm.o

$(LIB).la: LDFLAGS+= -rpath $(LIBDIR)
install/%.la: ILIBDIR= $(DESTDIR)/$(LIBDIR)
install: IINCDIR= $(DESTDIR)/$(INCDIR)/
#install: IMANDIR= $(DESTDIR)/$(MANDIR)/man3/

lib: $(LIB).la

%.lo: %.c
libtool --mode=compile --tag CC $(CC) $(CFLAGS) -c $<

$(LIB).la: $(shell echo $(OBJS) | sed 's/\.o/\.lo/g')
libtool --mode=link --tag CC $(CC) $(LDFLAGS) -o $@ $(notdir $^)

install/%.la: %.la
mkdir -p $(ILIBDIR)
libtool --mode=install install -c $(notdir $@) $(ILIBDIR)/$(notdir $@)

install: $(addprefix install/,$(LIB).la)
libtool --mode=finish $(LIBDIR)
mkdir -p $(IINCDIR) && install -c $(INCS) $(IINCDIR)
#mkdir -p $(IMANDIR) && install -c $(MANS) $(IMANDIR)

tests: $(OBJS) t_lpm.o
$(CC) $(CFLAGS) $^ -o t_lpm
./t_lpm

clean:
libtool --mode=clean rm
@ rm -rf .libs *.o *.lo *.la t_lpm

.PHONY: all lib install tests clean
Loading

0 comments on commit fabdf67

Please sign in to comment.