logging: Switch to using libosmocore logging for all the code

This commit is contained in:
Holger Hans Peter Freyther
2014-12-04 16:32:37 +01:00
parent e527ef105f
commit 9c7fd8edc4
16 changed files with 184 additions and 932 deletions

View File

@@ -48,7 +48,7 @@ AC_SUBST(EXEC_LDADD)
# Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h syslog.h unistd.h])
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h])
# Check for if header
AC_CHECK_HEADERS([linux/if.h net/if.h])

View File

@@ -1,48 +0,0 @@
# Process this file with autoconf to produce a configure script.
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([sgsnemu/cmdline.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_AWK
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_RANLIB
# Checks for libraries.
# FIXME: Replace `main' with a function in `-le':
AC_CHECK_LIB([e], [main])
# FIXME: Replace `main' with a function in `-lgtp':
AC_CHECK_LIB([gtp], [main])
# FIXME: Replace `main' with a function in `-links':
AC_CHECK_LIB([inks], [main])
# Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h syslog.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
# Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_CHECK_FUNCS([gethostbyname inet_ntoa memset select socket strdup strerror strtol])
AC_CONFIG_FILES([Makefile
doc/Makefile
ggsn/Makefile
gtp/Makefile
intl/Makefile
po/Makefile
sgsnemu/Makefile
src/Makefile
tests/Makefile])
AC_OUTPUT

View File

@@ -95,9 +95,8 @@ radio access network and the SGSN. When a connection request is
received the ggsn will allocate a dynamic IP address for the mobile
station, and allow the mobile station to access the Gi
interface. Connections are terminated by either the mobile station or
the SGSN. Runtime errors are reported using the
.B syslogd (8)
facility.
the SGSN. Runtime errors are reported using the Osmocom logging
framework.
Typically
.B ggsn
@@ -219,8 +218,7 @@ billing mechanisms are missing.
.SH "SEE ALSO"
.BR sgsnemu (8),
.BR syslogd (8)
.BR sgsnemu (8)
.SH NOTES
.LP

View File

@@ -1,272 +0,0 @@
.\" * OpenGGSN - Gateway GPRS Support Node
.\" * Copyright (C) 2002, 2003 Mondru AB.
.\" * Polish translation copyright (C) 2004 Marek <20>akowicz <mazaczek@users.sourceforge.net>
.\" *
.\" * The contents of this file may be used under the terms of the GNU
.\" * General Public License Version 2, provided that the above copyright
.\" * notice and this permission notice is included in all copies or
.\" * substantial portions of the software.
.\" *
.\" * The initial developer of the original code is
.\" * Jens Jakobsen <jj@openggsn.org>
.\" *
.\" * Contributor(s):
.\" *
.\" * Translation to polish: Marek Zakowicz <mazak@debian.linux.org.pl>
.\" Manual page for ggsn
.\" SH section heading
.\" SS subsection heading
.\" LP paragraph
.\" IP indented paragraph
.\" TP hanging label
.TH ggsn 8 "Lipiec 2003"
.SH NAZWA
ggsn \- W<>ze<7A> Wspieraj<61>cy Bramy GPRS (ang. Gateway GPRS Support Node).
.SH U<>YTKOWANIE
.B ggsn
\-\-help
.B ggsn
\-\-version
.B ggsn
[
.BI \-\-fg
] [
.BI \-\-debug
] [
.BI \-\-conf " plik"
] [
.BI \-\-pidfile " plik"
] [
.BI \-\-statedir " plik"
] [
.BI \-\-listen " host"
] [
.BI \-\-net " sie<EFBFBD>"
] [
.BI \-\-ipup " skrypt"
] [
.BI \-\-ipdown " skrypt"
] [
.BI \-\-dynip " sie<EFBFBD>"
] [
.BI \-\-statip " sie<EFBFBD>"
] [
.BI \-\-pcodns1 " host"
] [
.BI \-\-pcodns2 " host"
] [
.BI \-\-timelimit " sekundy"
]
.SH OPIS
.B ggsn
jest cz<63><7A>ci<63> projektu
.B OpenGGSN
i implementuje funkcjonalno<6E><6F> w<>z<EFBFBD>a wspieraj<61>cego bramy GPRS.
W<EFBFBD>z<EFBFBD>y GGSN s<> wykorzystywane przez operator<6F>w sieci kom<6F>rkowych jako interfejsy
pomi<EFBFBD>dzy Internetem i reszt<7A> infrastruktury sieci kom<6F>rkowej.
Funkcjonalno<EFBFBD><EFBFBD> i protoko<6B>y GPRS zosta<74>y ustandaryzowane w ramach projektu
Third Generation Partnership Project (3GPP). Stosownie do specyfikacji 3GPP,
GGSN posiada dwa interfejsy: interfejs Gn/Gp oraz interfejs Gi.
Interfejs Gn/Gp mo<6D>e by<62> postrzegany jako <20><>cze podrz<72>dne w<>z<EFBFBD>a GGSN.
Jest on wykorzystywany do komunikacji z W<>z<EFBFBD>em Dostarczaj<61>cym Us<55>ug GPRS
(SGSN), kt<6B>ry z kolei jest interfejsem do radiowej sieci dost<73>powej.
Interfejs Gn/Gp wykorzystuje protok<6F><6B> tunelowania GPRS (GTP). Pakiety danych
u<EFBFBD>ytkownika (zazwyczaj pakiety IP) s<> tunelowane za po<70>rednictwem protoko<6B>u GTP,
kt<EFBFBD>ry z kolei wykorzystuje protok<6F><6B> UDP nad IP.
Drugi z interfejs<6A>w mo<6D>e by<62> postrzegany jako <20><>cze nadrz<72>dne,
prowadz<EFBFBD>ce z w<>z<EFBFBD>a GGSN do zewn<77>trznej sieci danych.
Gi jest najcz<63><7A>ciej interfejsem do Internetu.
.B ggsn
wykorzystuje
.B sterownik TUN/TAP
jako interfejs Gi. Interfejs w sieci tun jest uruchamiany podczas startu
.B ggsn.
.B ggsn
odbiera po<70><6F>czenia nadchodz<64>ce od urz<72>dze<7A> ruchomych za po<70>rednictwem
sieci radiowej oraz SGSN. Gdy nadchodzi <20><>danie po<70><6F>czenia, ggsn rezerwuje
dla urz<72>dzenia ruchomego dynamiczny adres IP i pozwala urz<72>dzeniu ruchomemu
korzysta<EFBFBD> z interfejsu Gi. Po<50><6F>czenia mog<6F> by<62> zamykane zar<61>wno przez
stacje ruchome, jak i SGSN. B<><42>dy wyst<73>puj<75>ce podczas pracy programu
s<EFBFBD> raportowane z wykorzystaniem
.B syslogd (8).
W typowej sytuacji
.B ggsn
jest uruchamiany na komputerze z dwoma kartami Ethernet - jedn<64>
przeznaczon<EFBFBD> dla interfejsu Gn/Gp i jedn<64> dla interfejsu Gi.
Polityki trasowania i regu<67>y <20>ciany ogniowej powinny by<62> wykorzystane
w celu rozdzielenia ruchu Gi od ruchu Gn/Gp.
.SH OPCJE
.TP
.BI --help
Wy<EFBFBD>wietla pomoc i na tym ko<6B>czy wykonanie programu.
.TP
.BI --version
Wy<EFBFBD>wietla pomoc i na tym ko<6B>czy wykonanie programu.
.TP
.BI --fg
Uruchamia na pierwszym planie (domy<6D>lnie wy<77><79>czone).
.TP
.BI --debug
Uruchamia w trybie usuwania b<><62>d<EFBFBD>w (domy<6D>lnie wy<77><79>czone).
.TP
.BI --conf " plik"
Odczytuje konfiguracj<63> z
.I pliku
(domy<6D>lnie /etc/ggsn.conf), kt<6B>rego ka<6B>da linia odpowiada jednej opcji
linii polece<63> pozbawionej przedrostka '--'. Opcje podane w linii polece<63>
nadpisuj<EFBFBD> opcje podane w pliku konfiguracyjnym.
.TP
.BI --pidfile " plik"
Nazwa
.I pliku
z identyfikatorem procesu (domy<6D>lnie /var/run/ggsn.pid)
.TP
.BI --statedir " <EFBFBD>cie<EFBFBD>ka"
.I <20>cie<69>ka
do katalogu z trwa<77>ymi (nie ulotnymi) danymi (domy<6D>lnie /var/lib/ggsn/)
.TP
.BI --listen " host"
Lokalny adres IP, kt<6B>ry zostanie u<>yty do nas<61>uchu przez interfejs Gn/Gp.
Ta opcja musi zosta<74> podana.
Z przyczyn bezpiecze<7A>stwa nie mo<6D>e by<62> wykorzystany INADDR_ANY.
.TP
.BI --net " sie<EFBFBD>"
Adres sieci interfejsu Gi (domy<6D>lnie 192.168.0.0/24).
Adres sieci jest ustawiany podczas inicjalizacji, gdy
.B ggsn
uruchamia urz<72>dzenie tun dla interfejsu Gi.
.TP
.BI --ipup " skrypt"
Skrypt wykonywany po aktywacji interfejsu Gi w sieci tun.
Skrypt jest uruchamiany z nast<73>puj<75>cymi parametrami <nazwa urz<72>dzenia> <adres ip>.
.TP
.BI --ipdown " skrypt"
Skrypt wykonywany po wy<77><79>czeniu interfejsu Gi w sieci tun.
Skrypt jest uruchamiany z nast<73>puj<75>cymi parametrami <nazwa urz<72>dzenia> <adres ip>.
.TP
.BI --dynip " sie<EFBFBD>"
Pula dynamicznych adres<65>w sieci IP. Okre<72>la pul<75> dynamicznych adres<65>w IP.
Je<EFBFBD>li ta opcja zostanie pomini<6E>ta, ggsn wykorzystuje do dynamicznej rezerwacji
adres<EFBFBD>w IP, adres sieci okre<72>lony przez opcj<63>
.BI --net.
.TP
.BI --pcodns1 " host"
Serwer PCO DNS 1 (domy<6D>lnie 0.0.0.0). PCO jest akronimem
Protocol Configuration Options, co t<>umaczy si<73> jako Protok<6F><6B> Opcji
Konfiguracyjnych i jest cz<63><7A>ci<63> specyfikacji prtoko<6B><6F>w GPRS. Jest
wykorzystywany do informowania stacji ruchomej o adresie serwera DNS
stosowanego do rozwi<77>zywania nazw host<73>w.
.TP
.BI --pcodns2 " host"
Serwer PCO DNS 2 (domy<6D>lnie 0.0.0.0). PCO jest akronimem
Protocol Configuration Options, co t<>umaczy si<73> jako Protok<6F><6B> Opcji
Konfiguracyjnych i jest cz<63><7A>ci<63> specyfikacji prtoko<6B><6F>w GPRS. Jest
wykorzystywany do informowania stacji ruchomej o adresie serwera DNS
stosowanego do rozwi<77>zywania nazw host<73>w.
.TP
.BI --timelimit " sekundy"
Ko<EFBFBD>czy wykonanie
.b ggsn
po up<75>ywie podanej liczy \fIsekund\fP.
Opcja wykorzystywana w celu usuwania b<><62>d<EFBFBD>w.
.SH PLIKI
.I /etc/ggsn.conf
.RS
Plik konfiguracyjny dla
.B ggsn.
.RE
.I /var/run/ggsn.pid
.RS
Plik zawieraj<61>cy identyfikator procesu.
.RE
.I /var/lib/ggsn
.RS
Katalog przechowuj<75>cy trwa<77>e (nie ulotne) dane.
.RE
.SH B<><42>DY
Zg<EFBFBD>aszaj b<><62>dy na list<73> <20>ledzenia b<><62>d<EFBFBD>w OpenGGSN
.I http://sourceforge.net/projects/ggsn/
.B ggsn
ma bardzo ograniczone wsparcie dla zarz<72>dzania.
Obecnie zar<61>wno SNMP jak i mechanizmy rozliczania s<> pomini<6E>te.
.SH "ZOBACZ TAK<EFBFBD>E"
.BR sgsnemu (8),
.BR syslogd (8)
.SH UWAGI
.LP
Opr<EFBFBD>cz d<EFBFBD>ugich, udokumentowanych w tym podr<EFBFBD>czniku, opcji
.B ggsn
wspiera r<EFBFBD>wnie<EFBFBD> pewn<EFBFBD> liczb<EFBFBD> kr<EFBFBD>tkich opcji o tej samej funkcjonalno<EFBFBD>ci.
Wywo<EFBFBD>aj
.B ggsn --help
by uzyska<EFBFBD> pe<EFBFBD>n<EFBFBD> list<EFBFBD> dost<EFBFBD>pnych opcji.
Sterownik TUN/TAP jest wymagany dla poprawnego dzia<EFBFBD>ania
.B ggsn.
Dla j<EFBFBD>der linuksa p<EFBFBD><EFBFBD>niejszych ni<EFBFBD> 2.4.7 sterownik TUN/TAP jest zawarty w j<EFBFBD>drze,
chocia<EFBFBD> w typowej sytuacji musi by<EFBFBD> <EFBFBD>adowany oddzielnie za pomoc<EFBFBD>
.B modprobe tun.
Aby <EFBFBD>adowa<EFBFBD> automatycznie nale<EFBFBD>y do pliku
.B /etc/modules.conf.
doda<EFBFBD> lini<EFBFBD>
.B alias char-major-10-200 tun
Aby uzyska<EFBFBD> informacje o innych platformach zobacz stron<EFBFBD>
.I http://vtun.sourceforge.net/tun/
opisuj<EFBFBD>c<EFBFBD> jak zainstalowa<EFBFBD> i skonfigurowa<EFBFBD> sterownik tun.
.B ggsn
wykorzystuje protok<EFBFBD><EFBFBD> tunelowania GPRS (GTP) wyspecyfikowany przez
Third Generation Partnership Project (3GPP). Specyfikacje protoko<EFBFBD><EFBFBD>w 3GPP
mog<EFBFBD> by<EFBFBD> znalezione na
.I http://www.3gpp.org
.SH COPYRIGHT
Copyright (C) 2002, 2003 by Mondru AB.
Zawarto<EFBFBD><EFBFBD> tego pliku mo<EFBFBD>e by<EFBFBD> wykorzystywana stosownie do termin<EFBFBD>w
Og<EFBFBD>lnej, Publicznej Licencji (GPL) GNU w wersji 2 dostarczonej wraz
z niniejsz<EFBFBD> uwag<EFBFBD> o prawach autorskich zawart<EFBFBD> we wszystkich kopiach
i istotnych fragmentach oprogramowania.
.SH AUTORZY
Jens Jakobsen <jj@openggsn.org>
.SH T<EFBFBD>UMACZENIE
Polish translation copyright (C) 2004 Marek <EFBFBD>akowicz <mazaczek@users.sourceforge.net>
T<EFBFBD>umaczenie jest chronione prawami autorskimi.
Dozwolone jest korzystanie, rozprowadzanie i modyfikacja na zasadach licencji GNU GPL 2.

View File

@@ -123,9 +123,7 @@ uses the
for the local interface. A tun network interface is established for
each connection established to the GGSN.
Runtime errors are reported using the
.B syslogd (8)
facility.
Runtime errors are reported using the Osmocom logging framework.
.SH OPTIONS
@@ -355,8 +353,7 @@ Report all bugs to the OpenGGSN bug tracking list at
.SH "SEE ALSO"
.BR ggsn (8),
.BR syslog (8)
.BR ggsn (8)
.SH NOTES
.LP

View File

@@ -1,407 +0,0 @@
.\" * OpenGGSN - Gateway GPRS Support Node
.\" * Copyright (C) 2002, 2003 Mondru AB.
.\" * Polish translation copyright (C) 2004 Marek <20>akowicz <mazaczek@users.sourceforge.net>
.\" *
.\" * The contents of this file may be used under the terms of the GNU
.\" * General Public License Version 2, provided that the above copyright
.\" * notice and this permission notice is included in all copies or
.\" * substantial portions of the software.
.\" *
.\" * The initial developer of the original code is
.\" * Jens Jakobsen <jj@openggsn.org>
.\" *
.\" * Contributor(s):
.\" *
.\" * Translation to polish: Marek Zakowicz <mazak@debian.linux.org.pl>
.\" Manual page for ggsn
.\" SH section heading
.\" SS subsection heading
.\" LP paragraph
.\" IP indented paragraph
.\" TP hanging label
.TH sgsnemu 8 "Maj 2004"
.SH NAZWA
sgsnemu \- Emulator W<>z<EFBFBD>a Dostarczaj<61>cego Us<55>ug GPRS
.SH U<>YTKOWANIE
.B sgsnemu
\-\-help
.B sgsnemu
\-\-version
.B sgsnemu
[
.BI \-\-debug
] [
.BI \-\-conf " plik"
] [
.BI \-\-pidfile " plik"
] [
.BI \-\-statedir " plik"
] [
.BI \-\-dns " host"
] [
.BI \-\-listen " host"
] [
.BI \-\-remote " host"
] [
.BI \-\-contexts " liczba"
] [
.BI \-\-timelimit " sekundy"
] [
.BI \-\-gtpversion " wersja"
] [
.BI \-\-apn " apn"
] [
.BI \-\-selmode " tryb"
] [
.BI \-\-imsi " imsi"
] [
.BI \-\-nsapi " nsapi"
] [
.BI \-\-msisdn " msisdn"
] [
.BI \-\-qos " qos"
] [
.BI \-\-charging " op<EFBFBD>ata"
] [
.BI \-\-uid " uid"
] [
.BI \-\-pwd " pwd"
] [
.BI \-\-createif
] [
.BI \-\-net " sie<EFBFBD>"
] [
.BI \-\-defaultroute
] [
.BI \-\-ipup " skrypt"
] [
.BI \-\-ipdown " skrypt"
] [
.BI \-\-pinghost " host"
] [
.BI \-\-pingrate " liczba"
] [
.BI \-\-pingsize " liczba"
] [
.BI \-\-pingcount " liczba"
]
.SH OPIS
.B sgsnemu
jest cz<63><7A>ci<63> projektu
.B OpenGGSN
i implementuje emulator w<>z<EFBFBD>a dostarczaj<61>cego us<75>ug GPRS (SGSN).
Mo<EFBFBD>e on by<62> wykorzystywany zar<61>wno do testowania w<>z<EFBFBD><7A>w GGSN,
jak rdzenia sieci GRPS, czy po<70><6F>cze<7A> odwiedzaj<61>cych.
Funkcjonalno<EFBFBD><EFBFBD> i protoko<6B>y GPRS zosta<74>y ustandaryzowane w ramach projektu
Third Generation Partnership Project (3GPP).
Wed<EFBFBD>ug specyfikacji 3GPP, SGSN posiada kilka interfejs<6A>w.
.B sgsnemu
implementuje interfejs Gn/Gp, kt<6B>ry jest wykorzystywany w kierunku
w<EFBFBD>z<EFBFBD><EFBFBD>w GGSN.
Interfejs Gn/Gp mo<6D>e by<62> postrzegany jako <20><>cze nadrz<72>dne w<>z<EFBFBD>a SGSN.
Jest ono wykorzystywane do komunikacji z w<>z<EFBFBD>em GGSN, kt<6B>ry zazwyczaj jest
pod<EFBFBD><EFBFBD>czony do Internetu.
Interfejs Gn/Gp wykorzystuje protok<6F><6B> tunelowania GPRS (GTP).
Pakiety u<>ytkownika (zazwyczaj pakiety IP) s<> tunelowane za po<70>rednictwem protoko<6B>u GTP,
kt<EFBFBD>ry z kolei wykorzystuje protok<6F><6B> UDP nad IP.
.B sgsnemu
ustanawia pewn<77> liczb<7A> po<70><6F>cze<7A> do GGSN.
Wewn<EFBFBD>trzny ping transmituje <20><>dania ICMP poprzez ju<6A> ustanowione po<70><6F>czenia.
Alternatywnie, mo<6D>e by<62> utworzony lokalny interfejs sieciowy.
W tym przypadku
.B sgsnemu
przekazuje pakiety pomi<6D>dzy lokalnym interfejsem sieciowym i po<70><6F>czeniami
ustanowionymi na interfejsie Gn/Gp.
.B sgsnemu
wykorzystuje sterownik
.B TUN/TAP
jako interfejs lokalny. Interfejs sieci tun jest ustanawiany dla ka<6B>dego
po<EFBFBD><EFBFBD>czenia zestawianego z w<>z<EFBFBD>em GGSN.
B<EFBFBD><EFBFBD>dy wyst<73>puj<75>ce podczas pracy programu s<> raportowane z wykorzystaniem
.B syslogd (8).
.SH OPCJE
.TP
.BI --help
Wy<EFBFBD>wietla pomoc i na tym ko<6B>czy wykonanie programu.
.TP
.BI --version
Wy<EFBFBD>wietla pomoc i na tym ko<6B>czy wykonanie programu.
.TP
.BI --debug
Uruchamia w trybie usuwania b<><62>d<EFBFBD>w (domy<6D>lnie wy<77><79>czone).
.TP
.BI --conf " plik"
Odczytuje konfiguracj<63> z
.I pliku
,kt<6B>rego ka<6B>da linia odpowiada jednej opcji
linii polece<63> pozbawionej przedrostka '--'. Opcje podane w linii polece<63>
nadpisuj<EFBFBD> opcje podane w pliku konfiguracyjnym.
.TP
.BI --pidfile " plik"
Nazwa
.I pliku
z identyfikatorem procesu (domy<6D>lnie ./sgsnemu.pid)
.TP
.BI --statedir " <EFBFBD>cie<EFBFBD>ka"
.I <20>cie<69>ka
do katalogu z trwa<77>ymi (nie ulotnymi) danymi (domy<6D>lnie ./)
.TP
.BI --dns " host"
Serwer DNS wykorzystywany do zapyta<74> APN.
Je<EFBFBD>li parametr zosta<74> pomini<6E>ty, wykorzystywana jest domy<6D>lna, systemowa konfiguracja DNS.
.TP
.BI --listen " host"
Lokalny adres IP, kt<6B>ry zostanie u<>yty do nas<61>uchu przez interfejs Gn/Gp.
Ta opcja musi zosta<74> podana.
Z przyczyn bezpiecze<7A>stwa nie mo<6D>e by<62> wykorzystany INADDR_ANY.
.TP
.BI --remote " host"
.I Host
z w<>z<EFBFBD>em GGSN wykorzystywanym do po<70><6F>cze<7A>. Je<4A>li DNS jest prawid<69>owo skonfigurowany
to powinno by<62> mo<6D>liwe podanie nazwy punktu dost<73>powego (APN) jako nazwy zdalnego hosta.
.TP
.BI --contexts " liczba"
Liczba ustanawianych kontekst<73>w (domy<6D>lnie = 1). W przypadku wielu kontekst<73>w
pierwszy kontekst jest ustanawiany z wykorzystaniem imsi + 0 i msidn + 0.
Drugi kontekst jest ustanawiany z wykorzystaniem imsi + 1 i msidn +1.
Trzeci ...
.TP
.BI --timelimit " sekundy"
Ko<EFBFBD>czy wykonanie
.b sgsnemu
po up<75>ywie podanej liczy \fIsekund\fP.
W przypadku wykorzystywania opcji ping mo<6D>na zako<6B>czy<7A>
.B sgsnemu
po wy<77>aniu
.B --pingcount
pakiet<EFBFBD>w.
.TP
.BI --gtpversion " wersja"
.I wersja
protoko<EFBFBD>u GTP wykorzystywana przy ustanawianiu kontekst<73>w (domy<6D>lnie = 1).
Je<EFBFBD>li nie jest mo<6D>liwe ustanowienie kontekstu GTPw1
.B sgsnemu
powt<EFBFBD>rzy <20><>danie wykorzystuj<75>c GTPw0.
.TP
.BI --apn " apn"
.I apn
wykorzystywany przy <20><>czeniu si<73> z w<>z<EFBFBD>em GGSN (domy<6D>lnie = internet).
APN jest akronimem angielskich s<><73>w Access Point Name.
.TP
.BI --selmode " tryb"
Tryb wyboru wykorzystywany w komunikacji z w<>z<EFBFBD>em GGSN (domy<6D>lnie = 0x01).
Jako tryby wyboru mog<6F> by<62> wykorzystane nast<73>puj<75>ce kody:
0: MS lub sie<69> dostarczana przez APN, subskrypcja zweryfikowana,
1: MS dostarczany przez APN, subskrypcja nie zweryfikowana,
2: sie<69> dostarczana przez APN, subskrypcja nie zweryfikowana.
.TP
.BI --imsi " imsi"
.I imsi
wykorzystywane w komunikacji z w<>z<EFBFBD>em GGSN (domy<6D>lnie = 240010123456789).
IMSI jest akronimem angielskich s<><73>w International Mobile Subscriber Identity.
IMSI musi sk<73>ada<64> si<73> z dok<6F>adnie 15 cyfr. Por<6F>wnaj z opcj<63>
.I contexts
by zobaczy<7A> wykorzystanie
.I imsi
w przypadku wielu kontekst<73>w.
.TP
.BI --nsapi " nsapi"
.I nsapi
wykorzystywane w komunikacji z w<>z<EFBFBD>em GGSN (domy<6D>lnie = 0).
Warto<EFBFBD><EFBFBD> musi by<62> pomi<6D>dzy 0, a 15.
.TP
.BI --msisdn " msisdn"
.I msisdn
wykorzystywane w komunikacji z w<>z<EFBFBD>em GGSN (domy<6D>lnie = 46702123456).
MSISDN jest akronimem angielskich s<><73>w International Mobile Integrated Services Digital Network.
W istocie jest numerem telefonu zapisanym w mi<6D>dzynarodowym formacie bez wiod<6F>cych 00 lub 011.
Por<EFBFBD>wnaj z opcj<63>
.I contexts
by zobaczy<7A> wykorzystanie
.I msisdn
w przypadku wielu kontekst<73>w.
.TP
.BI --qos " qos"
.I qos
wykorzystywany w komunikacji z w<>z<EFBFBD>em GGSN (domy<6D>lnie = 0x0b921f).
QoS jest akronimem angielskich s<><73>w Quality of Service.
Format tego parametru zosta<74> okre<72>lony na podstawie specyfikacji 3GPP 09.60.
.TP
.BI --charging " op<EFBFBD>ata"
Charakterystyka rozliczania wykorzystywana w komunikacji z w<>z<EFBFBD>em GGSN
(domy<6D>lnie = 0x0800). 0x0800 = normalna, 0x0400 = przedp<64>ata,
0x0200 = p<>aska rata, 0x0100 = rozliczanie dynamiczne.
Format pola zosta<74> opisany w specyfikacji 3GPP 32.015.
.TP
.BI --uid " uid"
Identyfikator u<>ytkownika wysy<73>any do GGSN jako opcja konfiguracyjna protoko<6B>u.
.TP
.BI --pwd " has<EFBFBD>o"
Identyfikator wysy<73>ane do GGSN jako opcja konfiguracyjna protoko<6B>u.
.TP
.BI --createif
Tworzy lokalny interfejs tun, wykorzystywany dla
przesy<EFBFBD>ania pakiet<65>w do i z interfejsu Gn/Gp.
Nale<EFBFBD>y zaznaczy<7A>, <20>e interfejs Gn/Gp zazwyczaj jest kierowany
do Internetu przez GGSN. Tylko jeden interfejs mo<6D>e by<62> utworzony, chocia<69>
wiele kontekst<73>w mo<6D>e zosta<74> ustanowionych.
Interfejs mo<6D>e by<62> podany dla ka<6B>dego kontekstu jako adres IP, lub mo<6D>e by<62>
okre<EFBFBD>lony za pomoc<6F> opcji
.I net.
.TP
.BI --net " sie<EFBFBD>"
Adres sieci lokalnego interfejsu.
Opcja
.I net
jest poprawna tylko wtedy, gdy zosta<74>a wykorzystana opcja
.I createif.
Warto<EFBFBD><EFBFBD> parametru
.I net
jest podawana w formacie cidr (sie<69>/maska). Je<4A>li opcja
.I net
zostanie pomini<6E>ta, adres IP jest rezerwowany dla ka<6B>dego ustanawianego kontekstu.
.TP
.BI --defaultroute
Definiuje domy<6D>lne trasowanie przez lokalny interfejs tun.
.TP
.BI --ipup " skrypt"
Skrypt wykonywany po aktywacji interfejsu Gi w sieci tun.
Skrypt jest uruchamiany z nast<73>puj<75>cymi parametrami <nazwa urz<72>dzenia> <adres ip>.
.TP
.BI --ipdown " skrypt"
Skrypt wykonywany po wy<77><79>czeniu interfejsu Gi w sieci tun.
Skrypt jest uruchamiany z nast<73>puj<75>cymi parametrami <nazwa urz<72>dzenia> <adres ip>.
.TP
.BI --pinghost " host"
Powoduje wysy<73>anie pakiet<65>w ICMP do urz<72>dzenia
.I host
poprzez interfejs Gn/Gp. Statystyki po<70><6F>cze<7A> s<> raportowane w formie
bardzo zbli<6C>onej do wyj<79>cia oryginalnego programu ping. Mo<4D>esz wykorzysta<74>
to udogodnienie do testowania wydajno<6E>ci GGSN.
.TP
.BI --pingrate " liczba"
Ilo<EFBFBD><EFBFBD> <20><>da<64> ICMP generowanych w przeci<63>gu sekundy (domy<6D>lnie = 1).
.TP
.BI --pingsize " liczba"
Rozmiar generowanych <20><>da<64> ICMP wyra<72>ony w oktetach (domy<6D>lnie = 56).
.TP
.BI --pingcount " liczba"
Oczekiwana ilo<6C><6F> wygenerowanych <20><>da<64> ICMP (domy<6D>lnie = 0).
Warto<EFBFBD><EFBFBD> 0 (zero) oznacza wielko<6B><6F> nieograniczon<6F>.
.TP
.BI --pingquiet
Wy<EFBFBD><EFBFBD>cza wypisywanie informacji o otrzymanych pakietach (domy<6D>lnie pakiety s<> wypisywane).
Jest to ca<63>kiem przydatne dla du<64>ych ilo<6C>ci pakiet<65>w ICMP generowanych w przeci<63>gu sekundy
(por<6F>wnaj z opcj<63> pingrate).
.SH PLIKI
.I sgsnemu.conf
.RS
Plik konfiguracyjny dla
.B sgsnemu.
.RE
.I .sgsnemu.pid
.RS
Plik zawieraj<61>cy identyfikator procesu.
.RE
.I ./
.RS
Katalog przechowuj<75>cy trwa<77>e (nie ulotne) dane.
.RE
.SH B<><42>DY
Zg<EFBFBD>aszaj b<><62>dy na list<73> <20>ledzenia b<><62>d<EFBFBD>w OpenGGSN
.I http://sourceforge.net/projects/sgsnemu/
.SH "ZOBACZ TAK<EFBFBD>E"
.BR ggsn (8),
.BR syslog (8)
.SH UWAGI
.LP
Opr<EFBFBD>cz d<EFBFBD>ugich, udokumentowanych w tym podr<EFBFBD>czniku, opcji
.B sgsnemu
wspiera r<EFBFBD>wnie<EFBFBD> pewn<EFBFBD> liczb<EFBFBD> kr<EFBFBD>tkich opcji o tej samej funkcjonalno<EFBFBD>ci.
Wywo<EFBFBD>aj
.B sgsnemu --help
by uzyska<EFBFBD> pe<EFBFBD>n<EFBFBD> list<EFBFBD> dost<EFBFBD>pnych opcji.
Sterownik TUN/TAP jest wymagany dla poprawnego dzia<EFBFBD>ania
.B sgsnemu.
Dla j<EFBFBD>der linuksa p<EFBFBD><EFBFBD>niejszych ni<EFBFBD> 2.4.7 sterownik TUN/TAP jest zawarty w j<EFBFBD>drze,
chocia<EFBFBD> w typowej sytuacji musi by<EFBFBD> <EFBFBD>adowany oddzielnie za pomoc<EFBFBD>
.B modprobe tun.
Aby <EFBFBD>adowa<EFBFBD> automatycznie nale<EFBFBD>y do pliku
.B /etc/modules.conf.
doda<EFBFBD> lini<EFBFBD>
.B alias char-major-10-200 tun
Aby uzyska<EFBFBD> informacje o innych platformach zobacz stron<EFBFBD>
.I http://vtun.sourceforge.net/tun/
opisuj<EFBFBD>c<EFBFBD> jak zainstalowa<EFBFBD> i skonfigurowa<EFBFBD> sterownik tun.
.B ggsn
wykorzystuje protok<EFBFBD><EFBFBD> tunelowania GPRS (GTP) wyspecyfikowany przez
Third Generation Partnership Project (3GPP). Specyfikacje protoko<EFBFBD><EFBFBD>w 3GPP
mog<EFBFBD> by<EFBFBD> znalezione na
.I http://www.3gpp.org
.SH COPYRIGHT
Copyright (C) 2002, 2003, 2004 by Mondru AB.
Zawarto<EFBFBD><EFBFBD> tego pliku mo<EFBFBD>e by<EFBFBD> wykorzystywana stosownie do termin<EFBFBD>w
Og<EFBFBD>lnej, Publicznej Licencji (GPL) GNU w wersji 2 dostarczonej wraz
z niniejsz<EFBFBD> uwag<EFBFBD> o prawach autorskich zawart<EFBFBD> we wszystkich kopiach
i istotnych fragmentach oprogramowania.
.SH AUTORZY
Jens Jakobsen <jj@openggsn.org>
.SH T<EFBFBD>UMACZENIE
Polish translation copyright (C) 2004 Marek <EFBFBD>akowicz <mazaczek@users.sourceforge.net>
T<EFBFBD>umaczenie jest chronione prawami autorskimi.
Dozwolone jest korzystanie, rozprowadzanie i modyfikacja na zasadach licencji GNU GPL 2.

View File

@@ -2,9 +2,9 @@ bin_PROGRAMS = ggsn
AM_LDFLAGS = @EXEC_LDFLAGS@
AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb
AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS)
ggsn_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a
ggsn_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS)
ggsn_DEPENDENCIES = ../gtp/libgtp.la ../lib/libmisc.a
ggsn_SOURCES = ggsn.c cmdline.c cmdline.h

View File

@@ -19,11 +19,12 @@
#include "../config.h"
#include <osmocom/core/application.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <syslog.h>
#include <ctype.h>
#include <netdb.h>
#include <signal.h>
@@ -88,7 +89,7 @@ void log_pid(char *pidfile)
file = fopen(pidfile, "w");
umask(oldmask);
if (!file) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to create process ID file: %s!", pidfile);
return;
}
@@ -149,7 +150,7 @@ int delete_context(struct pdp_t *pdp)
if (pdp->peer)
ippool_freeip(ippool, (struct ippoolm_t *)pdp->peer);
else
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Peer not defined!");
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Peer not defined!");
return 0;
}
@@ -240,15 +241,7 @@ int main(int argc, char **argv)
int timelimit; /* Number of seconds to be connected */
int starttime; /* Time program was started */
/* open a connection to the syslog daemon */
/*openlog(PACKAGE, LOG_PID, LOG_DAEMON); */
/* TODO: Only use LOG__PERROR for linux */
#ifdef __linux__
openlog(PACKAGE, (LOG_PID | LOG_PERROR), LOG_DAEMON);
#else
openlog(PACKAGE, (LOG_PID), LOG_DAEMON);
#endif
osmo_init_logging(&log_info);
if (cmdline_parser(argc, argv, &args_info) != 0)
exit(1);
@@ -286,13 +279,18 @@ int main(int argc, char **argv)
/* Open a log file */
if (args_info.logfile_arg) {
FILE* log_file = fopen(args_info.logfile_arg, "a");
if (!log_file) {
printf("Failed to open logfile: '%s'\n",
args_info.logfile_arg);
exit(1);
struct log_target *tgt;
tgt = log_target_find(LOG_TGT_TYPE_FILE, args_info.logfile_arg);
if (!tgt) {
tgt = log_target_create_file(args_info.logfile_arg);
if (!tgt) {
LOGP(DGGSN, LOGL_ERROR,
"Failed to create logfile: %s\n",
args_info.logfile_arg);
exit(1);
}
log_add_target(tgt);
}
sys_err_setlogfile(log_file);
}
if (args_info.debug_flag) {
@@ -332,7 +330,7 @@ int main(int argc, char **argv)
/* required for create_pdp_context_response messages */
if (args_info.listen_arg) {
if (!(host = gethostbyname(args_info.listen_arg))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Invalid listening address: %s!",
args_info.listen_arg);
exit(1);
@@ -340,7 +338,7 @@ int main(int argc, char **argv)
memcpy(&listen_.s_addr, host->h_addr, host->h_length);
}
} else {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Listening address must be specified! "
"Please use command line option --listen or "
"edit %s configuration file\n", args_info.conf_arg);
@@ -351,7 +349,7 @@ int main(int argc, char **argv)
/* Store net as in_addr net and mask */
if (args_info.net_arg) {
if (ippool_aton(&net, &mask, args_info.net_arg, 0)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Invalid network address: %s!",
args_info.net_arg);
exit(1);
@@ -359,7 +357,7 @@ int main(int argc, char **argv)
netaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
destaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
} else {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Network address must be specified: %s!",
args_info.net_arg);
exit(1);
@@ -370,7 +368,7 @@ int main(int argc, char **argv)
if (ippool_new(&ippool, args_info.net_arg, NULL, 1, 0,
IPPOOL_NONETWORK | IPPOOL_NOGATEWAY |
IPPOOL_NOBROADCAST)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to allocate IP pool!");
exit(1);
}
@@ -378,7 +376,7 @@ int main(int argc, char **argv)
if (ippool_new(&ippool, args_info.dynip_arg, NULL, 1, 0,
IPPOOL_NONETWORK | IPPOOL_NOGATEWAY |
IPPOOL_NOBROADCAST)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to allocate IP pool!");
exit(1);
}
@@ -389,7 +387,7 @@ int main(int argc, char **argv)
dns1.s_addr = 0;
if (args_info.pcodns1_arg) {
if (0 == inet_aton(args_info.pcodns1_arg, &dns1)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to convert pcodns1!");
exit(1);
}
@@ -397,7 +395,7 @@ int main(int argc, char **argv)
dns2.s_addr = 0;
if (args_info.pcodns2_arg) {
if (0 == inet_aton(args_info.pcodns2_arg, &dns2)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to convert pcodns2!");
exit(1);
}
@@ -407,7 +405,7 @@ int main(int argc, char **argv)
if (args_info.pcodns1_arg) {
dns1.s_addr = inet_addr(args_info.pcodns1_arg);
if (dns1.s_addr == -1) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to convert pcodns1!");
exit(1);
}
@@ -416,7 +414,7 @@ int main(int argc, char **argv)
if (args_info.pcodns2_arg) {
dns2.s_addr = inet_addr(args_info.pcodns2_arg);
if (dns2.s_addr == -1) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to convert pcodns2!");
exit(1);
}
@@ -469,32 +467,29 @@ int main(int argc, char **argv)
if (!args_info.fg_flag) {
FILE *f;
int rc;
closelog();
/* Close the standard file descriptors. */
/* Is this really needed ? */
f = freopen("/dev/null", "w", stdout);
if (f == NULL) {
sys_err(LOG_WARNING, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_NOTICE, 0,
"Could not redirect stdout to /dev/null");
}
f = freopen("/dev/null", "w", stderr);
if (f == NULL) {
sys_err(LOG_WARNING, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_NOTICE, 0,
"Could not redirect stderr to /dev/null");
}
f = freopen("/dev/null", "r", stdin);
if (f == NULL) {
sys_err(LOG_WARNING, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_NOTICE, 0,
"Could not redirect stdin to /dev/null");
}
rc = daemon(0, 0);
if (rc != 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, rc,
SYS_ERR(DGGSN, LOGL_ERROR, rc,
"Could not daemonize");
exit(1);
}
/* Open log again. This time with new pid */
openlog(PACKAGE, LOG_PID, LOG_DAEMON);
}
/* pidfile */
@@ -507,7 +502,7 @@ int main(int argc, char **argv)
printf("gtpclient: Initialising GTP tunnel\n");
if (gtp_new(&gsn, args_info.statedir_arg, &listen_, GTP_MODE_GGSN)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Failed to create gtp");
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to create gtp");
exit(1);
}
if (gsn->fd0 > maxfd)
@@ -525,7 +520,7 @@ int main(int argc, char **argv)
if (debug)
printf("Creating tun interface\n");
if (tun_new((struct tun_t **)&tun)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Failed to create tun");
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to create tun");
if (debug)
printf("Failed to create tun\n");
exit(1);
@@ -534,7 +529,7 @@ int main(int argc, char **argv)
if (debug)
printf("Setting tun IP address\n");
if (tun_setaddr(tun, &netaddr, &destaddr, &mask)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Failed to set tun IP address");
if (debug)
printf("Failed to set tun IP address\n");
@@ -565,7 +560,7 @@ int main(int argc, char **argv)
gtp_retranstimeout(gsn, &idleTime);
switch (select(maxfd + 1, &fds, NULL, NULL, &idleTime)) {
case -1: /* errno == EINTR : unblocked signal */
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"select() returned -1");
/* On error, select returns without modifying fds */
FD_ZERO(&fds);
@@ -580,7 +575,7 @@ int main(int argc, char **argv)
if (tun->fd != -1 && FD_ISSET(tun->fd, &fds) &&
tun_decaps(tun) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"TUN read failed (fd)=(%d)", tun->fd);
}

View File

@@ -4,4 +4,4 @@ noinst_HEADERS = gnugetopt.h ippool.h lookup.h syserr.h tun.h
AM_CFLAGS = -O2 -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb
libmisc_a_SOURCES = getopt1.c getopt.c ippool.c lookup.c syserr.c tun.c
libmisc_a_SOURCES = getopt1.c getopt.c ippool.c lookup.c tun.c debug.c

34
lib/debug.c Normal file
View File

@@ -0,0 +1,34 @@
/*
* (C) 2014 by Holger Hans Peter Freyther
*/
#include "syserr.h"
#include <osmocom/core/utils.h>
static const struct log_info_cat default_categories[] = {
[DIP] = {
.name = "DIP",
.description = "IP Pool and other groups",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
[DTUN] = {
.name = "DTUN",
.description = "Tunnel interface",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
[DGGSN] = {
.name = "DGGSN",
.description = "GGSN",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
[DSGSN] = {
.name = "DSGSN",
.description = "SGSN Emulator",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
};
const struct log_info log_info = {
.cat = default_categories,
.num_cat = ARRAY_SIZE(default_categories),
};

View File

@@ -13,7 +13,6 @@
#include <netinet/in.h> /* in_addr */
#include <stdlib.h> /* calloc */
#include <stdio.h> /* sscanf */
#include <syslog.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@@ -76,7 +75,7 @@ int ippool_hashdel(struct ippool_t *this, struct ippoolm_t *member)
}
if (p != member) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"ippool_hashdel: Tried to delete member not in hash table");
return -1;
}
@@ -124,31 +123,31 @@ int ippool_aton(struct in_addr *addr, struct in_addr *mask,
break;
case 5:
if (m1 > 32) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Invalid mask");
SYS_ERR(DIP, LOGL_ERROR, 0, "Invalid mask");
return -1; /* Invalid mask */
}
mask->s_addr = htonl(0xffffffff << (32 - m1));
break;
case 8:
if (m1 >= 256 || m2 >= 256 || m3 >= 256 || m4 >= 256) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Invalid mask");
SYS_ERR(DIP, LOGL_ERROR, 0, "Invalid mask");
return -1; /* Wrong mask format */
}
m = m1 * 0x1000000 + m2 * 0x10000 + m3 * 0x100 + m4;
for (masklog = 0; ((1 << masklog) < ((~m) + 1)); masklog++) ;
if (((~m) + 1) != (1 << masklog)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Invalid mask");
SYS_ERR(DIP, LOGL_ERROR, 0, "Invalid mask");
return -1; /* Wrong mask format (not all ones followed by all zeros) */
}
mask->s_addr = htonl(m);
break;
default:
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Invalid mask");
SYS_ERR(DIP, LOGL_ERROR, 0, "Invalid mask");
return -1; /* Invalid mask */
}
if (a1 >= 256 || a2 >= 256 || a3 >= 256 || a4 >= 256) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Wrong IP address format");
return -1;
} else
@@ -179,7 +178,7 @@ int ippool_new(struct ippool_t **this, char *dyn, char *stat,
dynsize = 0;
} else {
if (ippool_aton(&addr, &mask, dyn, 0)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Failed to parse dynamic pool");
return -1;
}
@@ -205,7 +204,7 @@ int ippool_new(struct ippool_t **this, char *dyn, char *stat,
statmask.s_addr = 0;
} else {
if (ippool_aton(&stataddr, &statmask, stat, 0)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Failed to parse static range");
return -1;
}
@@ -219,7 +218,7 @@ int ippool_new(struct ippool_t **this, char *dyn, char *stat,
listsize = dynsize + statsize; /* Allocate space for static IP addresses */
if (!(*this = calloc(sizeof(struct ippool_t), 1))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Failed to allocate memory for ippool");
return -1;
}
@@ -231,7 +230,7 @@ int ippool_new(struct ippool_t **this, char *dyn, char *stat,
(*this)->listsize += listsize;
if (!((*this)->member = calloc(sizeof(struct ippoolm_t), listsize))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Failed to allocate memory for members in ippool");
return -1;
}
@@ -249,7 +248,7 @@ int ippool_new(struct ippool_t **this, char *dyn, char *stat,
if (!
((*this)->hash =
calloc(sizeof(struct ippoolm_t), (*this)->hashsize))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Failed to allocate memory for hash members in ippool");
return -1;
}
@@ -333,7 +332,7 @@ int ippool_getip(struct ippool_t *this, struct ippoolm_t **member,
}
if (member)
*member = NULL;
/*sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Address could not be found"); */
/*SYS_ERR(DIP, LOGL_ERROR, 0, "Address could not be found"); */
return -1;
}
@@ -369,19 +368,19 @@ int ippool_newip(struct ippool_t *this, struct ippoolm_t **member,
/* First check to see if this type of address is allowed */
if ((addr) && (addr->s_addr) && statip) { /* IP address given */
if (!this->allowstat) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Static IP address not allowed");
return -1;
}
if ((addr->s_addr & this->statmask.s_addr) !=
this->stataddr.s_addr) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Static out of range");
return -1;
}
} else {
if (!this->allowdyn) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Dynamic IP address not allowed");
return -1;
}
@@ -407,7 +406,7 @@ int ippool_newip(struct ippool_t *this, struct ippoolm_t **member,
/* If not found yet and dynamic IP then allocate dynamic IP */
if ((!p2) && (!statip)) {
if (!this->firstdyn) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"No more IP addresses available");
return -1;
} else
@@ -416,7 +415,7 @@ int ippool_newip(struct ippool_t *this, struct ippoolm_t **member,
if (p2) { /* Was allocated from dynamic address pool */
if (p2->inuse) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"IP address allready in use");
return -1; /* Allready in use / Should not happen */
}
@@ -445,7 +444,7 @@ int ippool_newip(struct ippool_t *this, struct ippoolm_t **member,
if ((addr) && (addr->s_addr) && (statip)) { /* IP address given */
if (!this->firststat) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"No more IP addresses available");
return -1; /* No more available */
} else
@@ -471,7 +470,7 @@ int ippool_newip(struct ippool_t *this, struct ippoolm_t **member,
return 0; /* Success */
}
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Could not allocate IP address");
return -1; /* Should never get here. TODO: Bad code */
}
@@ -483,13 +482,13 @@ int ippool_freeip(struct ippool_t *this, struct ippoolm_t *member)
(void)ippool_printaddr(this);
if (!member->inuse) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Address not in use");
SYS_ERR(DIP, LOGL_ERROR, 0, "Address not in use");
return -1; /* Not in use: Should not happen */
}
switch (member->inuse) {
case 0: /* Not in use: Should not happen */
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Address not in use");
SYS_ERR(DIP, LOGL_ERROR, 0, "Address not in use");
return -1;
case 1: /* Allocated from dynamic address space */
/* Insert into list of unused */
@@ -526,7 +525,7 @@ int ippool_freeip(struct ippool_t *this, struct ippoolm_t *member)
(void)ippool_printaddr(this);
return 0;
default: /* Should not happen */
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DIP, LOGL_ERROR, 0,
"Could not free IP address");
return -1;
}

View File

@@ -1,51 +0,0 @@
/*
* Syslog functions.
* Copyright (C) 2003, 2004 Mondru AB.
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
#include <stdarg.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <syslog.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "syserr.h"
static FILE* err_log;
void sys_err_setlogfile(FILE* log)
{
err_log = log;
}
void sys_err(int pri, char *fn, int ln, int en, char *fmt, ...)
{
va_list args;
char buf[SYSERR_MSGSIZE];
va_start(args, fmt);
vsnprintf(buf, SYSERR_MSGSIZE, fmt, args);
va_end(args);
buf[SYSERR_MSGSIZE - 1] = 0; /* Make sure it is null terminated */
if (en) {
if (err_log)
fprintf(err_log, "%s: %d: %d (%s) %s\n",
fn, ln, en, strerror(en), buf);
syslog(pri, "%s: %d: %d (%s) %s", fn, ln, en, strerror(en),
buf);
} else {
if (err_log)
fprintf(err_log, "%s: %d: %s\n", fn, ln, buf);
syslog(pri, "%s: %d: %s", fn, ln, buf);
}
}

View File

@@ -12,10 +12,25 @@
#ifndef _SYSERR_H
#define _SYSERR_H
#define SYSERR_MSGSIZE 256
#include <osmocom/core/logging.h>
void sys_err_setlogfile(FILE*);
enum {
DIP,
DTUN,
DGGSN,
DSGSN,
};
void sys_err(int pri, char *filename, int en, int line, char *fmt, ...);
#define SYS_ERR(sub, pri, en, fmt, args...) \
if (en) { \
logp2(sub, pri, __FILE__, __LINE__, 0, \
"errno=%d/%s " fmt "\n", en, strerror(en), \
##args); \
} else { \
logp2(sub, pri, __FILE__, __LINE__, 0, \
fmt "\n", ##args); \
}
extern const struct log_info log_info;
#endif /* !_SYSERR_H */

View File

@@ -16,7 +16,6 @@
*
*/
#include <syslog.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -94,10 +93,10 @@ int tun_gifindex(struct tun_t *this, __u32 * index)
strncpy(ifr.ifr_name, this->devname, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
}
if (ioctl(fd, SIOCGIFINDEX, &ifr)) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "ioctl() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "ioctl() failed");
close(fd);
return -1;
}
@@ -117,10 +116,10 @@ int tun_sifflags(struct tun_t *this, int flags)
strncpy(ifr.ifr_name, this->devname, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
}
if (ioctl(fd, SIOCSIFFLAGS, &ifr)) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCSIFFLAGS) failed");
close(fd);
return -1;
@@ -162,7 +161,7 @@ int tun_addroute2(struct tun_t *this,
tun_nlattr(&req.n, sizeof(req), RTA_GATEWAY, gateway, 4);
if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"socket() failed");
return -1;
}
@@ -172,7 +171,7 @@ int tun_addroute2(struct tun_t *this,
local.nl_groups = 0;
if (bind(fd, (struct sockaddr*)&local, sizeof(local)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"bind() failed");
close(fd);
return -1;
@@ -180,21 +179,21 @@ int tun_addroute2(struct tun_t *this,
addr_len = sizeof(local);
if (getsockname(fd, (struct sockaddr*)&local, &addr_len) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"getsockname() failed");
close(fd);
return -1;
}
if (addr_len != sizeof(local)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DTUN, LOGL_ERROR, 0,
"Wrong address length %d", addr_len);
close(fd);
return -1;
}
if (local.nl_family != AF_NETLINK) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DTUN, LOGL_ERROR, 0,
"Wrong address family %d", local.nl_family);
close(fd);
return -1;
@@ -265,7 +264,7 @@ int tun_addaddr(struct tun_t *this,
tun_nlattr(&req.n, sizeof(req), IFA_LOCAL, dstaddr, sizeof(dstaddr));
if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
@@ -274,28 +273,28 @@ int tun_addaddr(struct tun_t *this,
local.nl_groups = 0;
if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "bind() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "bind() failed");
close(fd);
return -1;
}
addr_len = sizeof(local);
if (getsockname(fd, (struct sockaddr *)&local, &addr_len) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"getsockname() failed");
close(fd);
return -1;
}
if (addr_len != sizeof(local)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DTUN, LOGL_ERROR, 0,
"Wrong address length %d", addr_len);
close(fd);
return -1;
}
if (local.nl_family != AF_NETLINK) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DTUN, LOGL_ERROR, 0,
"Wrong address family %d", local.nl_family);
close(fd);
return -1;
@@ -361,12 +360,12 @@ int tun_addaddr(struct tun_t *this,
/* Create a channel to the NET kernel. */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
if (ioctl(fd, SIOCAIFADDR, (void *)&areq) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCAIFADDR) failed");
close(fd);
return -1;
@@ -381,7 +380,7 @@ int tun_addaddr(struct tun_t *this,
if (!this->addrs) /* Use ioctl for first addr to make ping work */
return tun_setaddr(this, addr, dstaddr, netmask);
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Setting multiple addresses not possible on Solaris");
return -1;
@@ -417,7 +416,7 @@ int tun_setaddr(struct tun_t *this,
/* Create a channel to the NET kernel. */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
@@ -427,10 +426,10 @@ int tun_setaddr(struct tun_t *this,
sizeof(*addr));
if (ioctl(fd, SIOCSIFADDR, (void *)&ifr) < 0) {
if (errno != EEXIST) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCSIFADDR) failed");
} else {
sys_err(LOG_WARNING, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_NOTICE, errno,
"ioctl(SIOCSIFADDR): Address already exists");
}
close(fd);
@@ -443,7 +442,7 @@ int tun_setaddr(struct tun_t *this,
memcpy(&((struct sockaddr_in *)&ifr.ifr_dstaddr)->sin_addr,
dstaddr, sizeof(*dstaddr));
if (ioctl(fd, SIOCSIFDSTADDR, (caddr_t) & ifr) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCSIFDSTADDR) failed");
close(fd);
return -1;
@@ -468,7 +467,7 @@ int tun_setaddr(struct tun_t *this,
#endif
if (ioctl(fd, SIOCSIFNETMASK, (void *)&ifr) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCSIFNETMASK) failed");
close(fd);
return -1;
@@ -510,7 +509,7 @@ int tun_route(struct tun_t *this,
/* Create a channel to the NET kernel. */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
@@ -525,14 +524,14 @@ int tun_route(struct tun_t *this,
if (delete) {
if (ioctl(fd, SIOCDELRT, (void *)&r) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCDELRT) failed");
close(fd);
return -1;
}
} else {
if (ioctl(fd, SIOCADDRT, (void *)&r) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCADDRT) failed");
close(fd);
return -1;
@@ -554,7 +553,7 @@ int tun_route(struct tun_t *this,
struct rt_msghdr *rtm;
if ((fd = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
@@ -586,7 +585,7 @@ int tun_route(struct tun_t *this,
req.gate.sin_addr.s_addr = gateway->s_addr;
if (write(fd, rtm, rtm->rtm_msglen) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "write() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "write() failed");
close(fd);
return -1;
}
@@ -594,7 +593,7 @@ int tun_route(struct tun_t *this,
return 0;
#elif defined(__sun__)
sys_err(LOG_WARNING, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_NOTICE, errno,
"Could not set up routing on Solaris. Please add route manually.");
return 0;
@@ -641,7 +640,7 @@ int tun_new(struct tun_t **tun)
#endif
if (!(*tun = calloc(1, sizeof(struct tun_t)))) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "calloc() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "calloc() failed");
return EOF;
}
@@ -652,7 +651,7 @@ int tun_new(struct tun_t **tun)
#if defined(__linux__)
/* Open the actual tun device */
if (((*tun)->fd = open("/dev/net/tun", O_RDWR)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "open() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "open() failed");
return -1;
}
@@ -661,7 +660,7 @@ int tun_new(struct tun_t **tun)
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; /* Tun device, no packet info */
if (ioctl((*tun)->fd, TUNSETIFF, (void *)&ifr) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "ioctl() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "ioctl() failed");
close((*tun)->fd);
return -1;
}
@@ -683,7 +682,7 @@ int tun_new(struct tun_t **tun)
break;
}
if ((*tun)->fd < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't find tunnel device");
return -1;
}
@@ -702,7 +701,7 @@ int tun_new(struct tun_t **tun)
/* Create a channel to the NET kernel. */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "socket() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
@@ -715,45 +714,45 @@ int tun_new(struct tun_t **tun)
#elif defined(__sun__)
if ((ip_fd = open("/dev/udp", O_RDWR, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't open /dev/udp");
return -1;
}
if (((*tun)->fd = open("/dev/tun", O_RDWR, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't open /dev/tun");
return -1;
}
/* Assign a new PPA and get its unit number. */
if ((ppa = ioctl((*tun)->fd, TUNNEWPPA, -1)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't assign new interface");
return -1;
}
if ((if_fd = open("/dev/tun", O_RDWR, 0)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't open /dev/tun (2)");
return -1;
}
if (ioctl(if_fd, I_PUSH, "ip") < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't push IP module");
return -1;
}
/* Assign ppa according to the unit number returned by tun device */
if (ioctl(if_fd, IF_UNITSEL, (char *)&ppa) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "Can't set PPA %d",
SYS_ERR(DTUN, LOGL_ERROR, errno, "Can't set PPA %d",
ppa);
return -1;
}
/* Link the two streams */
if ((muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't link TUN device to IP");
return -1;
}
@@ -769,7 +768,7 @@ int tun_new(struct tun_t **tun)
if (ioctl(ip_fd, SIOCSIFMUXID, &ifr) < 0) {
ioctl(ip_fd, I_PUNLINK, muxid);
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Can't set multiplexor id");
return -1;
}
@@ -793,7 +792,7 @@ int tun_free(struct tun_t *tun)
}
if (close(tun->fd)) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "close() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "close() failed");
}
/* TODO: For solaris we need to unlink streams */
@@ -818,7 +817,7 @@ int tun_decaps(struct tun_t *this)
int status;
if ((status = read(this->fd, buffer, sizeof(buffer))) <= 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "read() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "read() failed");
return -1;
}
@@ -836,7 +835,7 @@ int tun_decaps(struct tun_t *this)
sbuf.maxlen = PACKET_MAX;
sbuf.buf = buffer;
if (getmsg(this->fd, NULL, &sbuf, &f) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "getmsg() failed");
SYS_ERR(DTUN, LOGL_ERROR, errno, "getmsg() failed");
return -1;
}
@@ -885,7 +884,7 @@ int tun_runscript(struct tun_t *tun, char *script)
buf[sizeof(buf) - 1] = 0;
rc = system(buf);
if (rc == -1) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Error executing command %s", buf);
return -1;
}

View File

@@ -2,8 +2,8 @@ bin_PROGRAMS = sgsnemu
AM_LDFLAGS = @EXEC_LDFLAGS@
AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb
AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS)
sgsnemu_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a
sgsnemu_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS)
sgsnemu_DEPENDENCIES = ../gtp/libgtp.la ../lib/libmisc.a
sgsnemu_SOURCES = sgsnemu.c cmdline.c cmdline.h

View File

@@ -18,7 +18,8 @@
#define _GNU_SOURCE 1 /* strdup() prototype, broken arpa/inet.h */
#endif
#include <syslog.h>
#include <osmocom/core/application.h>
#include <ctype.h>
#include <netdb.h>
#include <signal.h>
@@ -377,7 +378,7 @@ int process_options(int argc, char **argv)
printf("\n");
if (args_info.dns_arg) {
if (!(host = gethostbyname(args_info.dns_arg))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Invalid DNS address: %s!", args_info.dns_arg);
return -1;
} else {
@@ -398,7 +399,7 @@ int process_options(int argc, char **argv)
/* Do hostname lookup to translate hostname to IP address */
if (args_info.listen_arg) {
if (!(host = gethostbyname(args_info.listen_arg))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Invalid listening address: %s!",
args_info.listen_arg);
return -1;
@@ -409,7 +410,7 @@ int process_options(int argc, char **argv)
args_info.listen_arg, inet_ntoa(options.listen));
}
} else {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Listening address must be specified: %s!",
args_info.listen_arg);
return -1;
@@ -420,7 +421,7 @@ int process_options(int argc, char **argv)
/* Do hostname lookup to translate hostname to IP address */
if (args_info.remote_arg) {
if (!(host = gethostbyname(args_info.remote_arg))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Invalid remote address: %s!",
args_info.remote_arg);
return -1;
@@ -431,7 +432,7 @@ int process_options(int argc, char **argv)
args_info.remote_arg, inet_ntoa(options.remote));
}
} else {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"No remote address given!");
return -1;
}
@@ -844,7 +845,7 @@ int process_options(int argc, char **argv)
if (args_info.net_arg) {
if (ippool_aton
(&options.net, &options.mask, args_info.net_arg, 0)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Invalid network address: %s!",
args_info.net_arg);
exit(1);
@@ -880,7 +881,7 @@ int process_options(int argc, char **argv)
/* Store ping host as in_addr */
if (args_info.pinghost_arg) {
if (!(host = gethostbyname(args_info.pinghost_arg))) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Invalid ping host: %s!",
args_info.pinghost_arg);
return -1;
@@ -1179,7 +1180,7 @@ int create_ping(void *gsn, struct pdp_t *pdp,
(struct timeval *)&p8[CREATEPING_IP + CREATEPING_ICMP];
if (datasize > CREATEPING_MAX) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Ping size to large: %d!", datasize);
return -1;
}
@@ -1410,15 +1411,7 @@ int main(int argc, char **argv)
struct timeval tv;
int diff;
/* open a connection to the syslog daemon */
/*openlog(PACKAGE, LOG_PID, LOG_DAEMON); */
/* TODO: Only use LOG__PERROR for linux */
#ifdef __linux__
openlog(PACKAGE, (LOG_PID | LOG_PERROR), LOG_DAEMON);
#else
openlog(PACKAGE, (LOG_PID), LOG_DAEMON);
#endif
osmo_init_logging(&log_info);
/* Process options given in configuration file and command line */
if (process_options(argc, argv))
@@ -1426,7 +1419,7 @@ int main(int argc, char **argv)
printf("\nInitialising GTP library\n");
if (gtp_new(&gsn, options.statedir, &options.listen, GTP_MODE_SGSN)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Failed to create gtp");
SYS_ERR(DSGSN, LOGL_ERROR, 0, "Failed to create gtp");
exit(1);
}
if (gsn->fd0 > maxfd)
@@ -1447,7 +1440,7 @@ int main(int argc, char **argv)
printf("Setting up interface\n");
/* Create a tunnel interface */
if (tun_new((struct tun_t **)&tun)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Failed to create tun");
exit(1);
}
@@ -1498,7 +1491,7 @@ int main(int argc, char **argv)
if (options.gtpversion == 0) {
if (options.qos.l - 1 > sizeof(pdp->qos_req0)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"QoS length too big");
exit(1);
} else {
@@ -1535,7 +1528,7 @@ int main(int argc, char **argv)
pdp->norecovery_given = options.norecovery_given;
if (options.apn.l > sizeof(pdp->apn_use.v)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"APN length too big");
exit(1);
} else {
@@ -1549,7 +1542,7 @@ int main(int argc, char **argv)
memcpy(pdp->gsnlu.v, &options.listen, sizeof(options.listen));
if (options.msisdn.l > sizeof(pdp->msisdn.v)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"MSISDN length too big");
exit(1);
} else {
@@ -1559,7 +1552,7 @@ int main(int argc, char **argv)
ipv42eua(&pdp->eua, NULL); /* Request dynamic IP address */
if (options.pco.l > sizeof(pdp->pco_req.v)) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"PCO length too big");
exit(1);
} else {
@@ -1674,7 +1667,7 @@ int main(int argc, char **argv)
switch (select(maxfd + 1, &fds, NULL, NULL, &idleTime)) {
case -1:
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"Select returned -1");
break;
case 0:
@@ -1685,7 +1678,7 @@ int main(int argc, char **argv)
}
if ((tun) && FD_ISSET(tun->fd, &fds) && tun_decaps(tun) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, 0,
SYS_ERR(DSGSN, LOGL_ERROR, 0,
"TUN decaps failed");
}