aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-12-04 16:32:37 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-12-04 16:51:15 +0100
commit9c7fd8edc4f114ea77b955fb7aaac51fb5c828d4 (patch)
treeea8273f03a9581474df87db998e464c8dae96fec
parente527ef105f8742b1e37677e58c5b69530e674cce (diff)
logging: Switch to using libosmocore logging for all the code
-rw-r--r--configure.in2
-rw-r--r--configure.scan48
-rw-r--r--doc/ggsn.88
-rw-r--r--doc/ggsn.8.pl272
-rw-r--r--doc/sgsnemu.87
-rw-r--r--doc/sgsnemu.8.pl407
-rw-r--r--ggsn/Makefile.am4
-rw-r--r--ggsn/ggsn.c75
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/debug.c34
-rw-r--r--lib/ippool.c45
-rw-r--r--lib/syserr.c51
-rw-r--r--lib/syserr.h21
-rw-r--r--lib/tun.c91
-rw-r--r--sgsnemu/Makefile.am4
-rw-r--r--sgsnemu/sgsnemu.c45
16 files changed, 184 insertions, 932 deletions
diff --git a/configure.in b/configure.in
index b9e052f..e31a79e 100644
--- a/configure.in
+++ b/configure.in
@@ -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])
diff --git a/configure.scan b/configure.scan
deleted file mode 100644
index ac79782..0000000
--- a/configure.scan
+++ /dev/null
@@ -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
diff --git a/doc/ggsn.8 b/doc/ggsn.8
index 7a98281..3b9e903 100644
--- a/doc/ggsn.8
+++ b/doc/ggsn.8
@@ -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
diff --git a/doc/ggsn.8.pl b/doc/ggsn.8.pl
deleted file mode 100644
index 35b116b..0000000
--- a/doc/ggsn.8.pl
+++ /dev/null
@@ -1,272 +0,0 @@
-
-.\" * OpenGGSN - Gateway GPRS Support Node
-.\" * Copyright (C) 2002, 2003 Mondru AB.
-.\" * Polish translation copyright (C) 2004 Marek Ż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ł Wspierają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ć"
-] [
-.BI \-\-ipup " skrypt"
-] [
-.BI \-\-ipdown " skrypt"
-] [
-.BI \-\-dynip " sieć"
-] [
-.BI \-\-statip " sieć"
-] [
-.BI \-\-pcodns1 " host"
-] [
-.BI \-\-pcodns2 " host"
-] [
-.BI \-\-timelimit " sekundy"
-]
-
-.SH OPIS
-.B ggsn
-jest częścią projektu
-.B OpenGGSN
-i implementuje funkcjonalność węzła wspierającego bramy GPRS.
-Węzły GGSN są wykorzystywane przez operatorów sieci komórkowych jako interfejsy
-pomiędzy Internetem i resztą infrastruktury sieci komórkowej.
-
-Funkcjonalność i protokoły GPRS został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że być postrzegany jako łącze podrzędne węzła GGSN.
-Jest on wykorzystywany do komunikacji z Węzłem Dostarczającym Usług GPRS
-(SGSN), który z kolei jest interfejsem do radiowej sieci dostępowej.
-Interfejs Gn/Gp wykorzystuje protokół tunelowania GPRS (GTP). Pakiety danych
-użytkownika (zazwyczaj pakiety IP) są tunelowane za pośrednictwem protokołu GTP,
-który z kolei wykorzystuje protokół UDP nad IP.
-
-Drugi z interfejsów może być postrzegany jako łącze nadrzędne,
-prowadzące z węzła GGSN do zewnętrznej sieci danych.
-Gi jest najczęś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łączenia nadchodzące od urządzeń ruchomych za pośrednictwem
-sieci radiowej oraz SGSN. Gdy nadchodzi żądanie połączenia, ggsn rezerwuje
-dla urządzenia ruchomego dynamiczny adres IP i pozwala urządzeniu ruchomemu
-korzystać z interfejsu Gi. Połączenia mogą być zamykane zarówno przez
-stacje ruchome, jak i SGSN. Błędy występujące podczas pracy programu
-są raportowane z wykorzystaniem
-.B syslogd (8).
-
-W typowej sytuacji
-.B ggsn
-jest uruchamiany na komputerze z dwoma kartami Ethernet - jedną
-przeznaczoną dla interfejsu Gn/Gp i jedną dla interfejsu Gi.
-Polityki trasowania i reguły ściany ogniowej powinny być wykorzystane
-w celu rozdzielenia ruchu Gi od ruchu Gn/Gp.
-
-.SH OPCJE
-.TP
-.BI --help
-Wyświetla pomoc i na tym kończy wykonanie programu.
-
-.TP
-.BI --version
-Wyświetla pomoc i na tym kończy wykonanie programu.
-
-.TP
-.BI --fg
-Uruchamia na pierwszym planie (domyślnie wyłączone).
-
-.TP
-.BI --debug
-Uruchamia w trybie usuwania błędów (domyślnie wyłączone).
-
-.TP
-.BI --conf " plik"
-Odczytuje konfigurację z
-.I pliku
-(domyślnie /etc/ggsn.conf), którego każda linia odpowiada jednej opcji
-linii poleceń pozbawionej przedrostka '--'. Opcje podane w linii poleceń
-nadpisują opcje podane w pliku konfiguracyjnym.
-
-.TP
-.BI --pidfile " plik"
-Nazwa
-.I pliku
-z identyfikatorem procesu (domyślnie /var/run/ggsn.pid)
-
-.TP
-.BI --statedir " ścieżka"
-.I Ścieżka
-do katalogu z trwałymi (nie ulotnymi) danymi (domyślnie /var/lib/ggsn/)
-
-.TP
-.BI --listen " host"
-Lokalny adres IP, który zostanie użyty do nasłuchu przez interfejs Gn/Gp.
-Ta opcja musi zostać podana.
-Z przyczyn bezpieczeństwa nie może być wykorzystany INADDR_ANY.
-
-.TP
-.BI --net " sieć"
-Adres sieci interfejsu Gi (domyślnie 192.168.0.0/24).
-Adres sieci jest ustawiany podczas inicjalizacji, gdy
-.B ggsn
-uruchamia urządzenie tun dla interfejsu Gi.
-
-.TP
-.BI --ipup " skrypt"
-Skrypt wykonywany po aktywacji interfejsu Gi w sieci tun.
-Skrypt jest uruchamiany z następującymi parametrami <nazwa urządzenia> <adres ip>.
-
-.TP
-.BI --ipdown " skrypt"
-Skrypt wykonywany po wyłączeniu interfejsu Gi w sieci tun.
-Skrypt jest uruchamiany z następującymi parametrami <nazwa urządzenia> <adres ip>.
-
-.TP
-.BI --dynip " sieć"
-Pula dynamicznych adresów sieci IP. Określa pulę dynamicznych adresów IP.
-Jeśli ta opcja zostanie pominięta, ggsn wykorzystuje do dynamicznej rezerwacji
-adresów IP, adres sieci określony przez opcję
-.BI --net.
-
-.TP
-.BI --pcodns1 " host"
-Serwer PCO DNS 1 (domyślnie 0.0.0.0). PCO jest akronimem
-Protocol Configuration Options, co tłumaczy się jako Protokół Opcji
-Konfiguracyjnych i jest częścią specyfikacji prtokołów GPRS. Jest
-wykorzystywany do informowania stacji ruchomej o adresie serwera DNS
-stosowanego do rozwiązywania nazw hostów.
-
-.TP
-.BI --pcodns2 " host"
-Serwer PCO DNS 2 (domyślnie 0.0.0.0). PCO jest akronimem
-Protocol Configuration Options, co tłumaczy się jako Protokół Opcji
-Konfiguracyjnych i jest częścią specyfikacji prtokołów GPRS. Jest
-wykorzystywany do informowania stacji ruchomej o adresie serwera DNS
-stosowanego do rozwiązywania nazw hostów.
-
-.TP
-.BI --timelimit " sekundy"
-Kończy wykonanie
-.b ggsn
-po upływie podanej liczy \fIsekund\fP.
-Opcja wykorzystywana w celu usuwania błędów.
-
-
-.SH PLIKI
-.I /etc/ggsn.conf
-.RS
-Plik konfiguracyjny dla
-.B ggsn.
-.RE
-.I /var/run/ggsn.pid
-.RS
-Plik zawierający identyfikator procesu.
-.RE
-.I /var/lib/ggsn
-.RS
-Katalog przechowujący trwałe (nie ulotne) dane.
-.RE
-
-.SH BŁĘDY
-Zgłaszaj błędy na listę śledzenia błędów OpenGGSN
-.I http://sourceforge.net/projects/ggsn/
-
-.B ggsn
-ma bardzo ograniczone wsparcie dla zarządzania.
-Obecnie zarówno SNMP jak i mechanizmy rozliczania są pominięte.
-
-.SH "ZOBACZ TAKŻE"
-.BR sgsnemu (8),
-.BR syslogd (8)
-
-.SH UWAGI
-.LP
-
-Oprócz długich, udokumentowanych w tym podręczniku, opcji
-.B ggsn
-wspiera również pewną liczbą krótkich opcji o tej samej funkcjonalności.
-Wywołaj
-.B ggsn --help
-by uzyskać pełną listę dostępnych opcji.
-
-Sterownik TUN/TAP jest wymagany dla poprawnego działania
-.B ggsn.
-Dla jąder linuksa późniejszych niż 2.4.7 sterownik TUN/TAP jest zawarty w jądrze,
-chociaż w typowej sytuacji musi być ładowany oddzielnie za pomocą
-.B modprobe tun.
-Aby ładować automatycznie należy do pliku
-.B /etc/modules.conf.
-dodać linię
-.B alias char-major-10-200 tun
-Aby uzyskać informacje o innych platformach zobacz stronę
-.I http://vtun.sourceforge.net/tun/
-opisującą jak zainstalować i skonfigurować sterownik tun.
-
-.B ggsn
-wykorzystuje protokół tunelowania GPRS (GTP) wyspecyfikowany przez
-Third Generation Partnership Project (3GPP). Specyfikacje protokołów 3GPP
-mogą być znalezione na
-.I http://www.3gpp.org
-
-.SH COPYRIGHT
-
-Copyright (C) 2002, 2003 by Mondru AB.
-
-Zawartość tego pliku może być wykorzystywana stosownie do terminów
-Ogólnej, Publicznej Licencji (GPL) GNU w wersji 2 dostarczonej wraz
-z niniejszą uwagą o prawach autorskich zawartą we wszystkich kopiach
-i istotnych fragmentach oprogramowania.
-
-.SH AUTORZY
-Jens Jakobsen <jj@openggsn.org>
-
-.SH TŁUMACZENIE
-Polish translation copyright (C) 2004 Marek Żakowicz <mazaczek@users.sourceforge.net>
-
-Tłumaczenie jest chronione prawami autorskimi.
-Dozwolone jest korzystanie, rozprowadzanie i modyfikacja na zasadach licencji GNU GPL 2.
diff --git a/doc/sgsnemu.8 b/doc/sgsnemu.8
index b273b4b..50502e0 100644
--- a/doc/sgsnemu.8
+++ b/doc/sgsnemu.8
@@ -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
diff --git a/doc/sgsnemu.8.pl b/doc/sgsnemu.8.pl
deleted file mode 100644
index cbdea48..0000000
--- a/doc/sgsnemu.8.pl
+++ /dev/null
@@ -1,407 +0,0 @@
-
-.\" * OpenGGSN - Gateway GPRS Support Node
-.\" * Copyright (C) 2002, 2003 Mondru AB.
-.\" * Polish translation copyright (C) 2004 Marek Ż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ła Dostarczającego Usł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łata"
-] [
-.BI \-\-uid " uid"
-] [
-.BI \-\-pwd " pwd"
-] [
-.BI \-\-createif
-] [
-.BI \-\-net " sieć"
-] [
-.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ęścią projektu
-.B OpenGGSN
-i implementuje emulator węzła dostarczającego usług GPRS (SGSN).
-Może on być wykorzystywany zarówno do testowania węzłów GGSN,
-jak rdzenia sieci GRPS, czy połączeń odwiedzających.
-
-Funkcjonalność i protokoły GPRS zostały ustandaryzowane w ramach projektu
-Third Generation Partnership Project (3GPP).
-Według specyfikacji 3GPP, SGSN posiada kilka interfejsów.
-.B sgsnemu
-implementuje interfejs Gn/Gp, który jest wykorzystywany w kierunku
-węzłów GGSN.
-
-Interfejs Gn/Gp może być postrzegany jako łącze nadrzędne węzła SGSN.
-Jest ono wykorzystywane do komunikacji z węzłem GGSN, który zazwyczaj jest
-podłączony do Internetu.
-Interfejs Gn/Gp wykorzystuje protokół tunelowania GPRS (GTP).
-Pakiety użytkownika (zazwyczaj pakiety IP) są tunelowane za pośrednictwem protokołu GTP,
-który z kolei wykorzystuje protokół UDP nad IP.
-
-
-.B sgsnemu
-ustanawia pewną liczbę połączeń do GGSN.
-Wewnętrzny ping transmituje żądania ICMP poprzez już ustanowione połączenia.
-Alternatywnie, może być utworzony lokalny interfejs sieciowy.
-W tym przypadku
-.B sgsnemu
-przekazuje pakiety pomiędzy lokalnym interfejsem sieciowym i połączeniami
-ustanowionymi na interfejsie Gn/Gp.
-
-.B sgsnemu
-wykorzystuje sterownik
-.B TUN/TAP
-jako interfejs lokalny. Interfejs sieci tun jest ustanawiany dla każdego
-połączenia zestawianego z węzłem GGSN.
-Błędy występujące podczas pracy programu są raportowane z wykorzystaniem
-.B syslogd (8).
-
-.SH OPCJE
-.TP
-.BI --help
-Wyświetla pomoc i na tym kończy wykonanie programu.
-
-.TP
-.BI --version
-Wyświetla pomoc i na tym kończy wykonanie programu.
-
-.TP
-.BI --debug
-Uruchamia w trybie usuwania błędów (domyślnie wyłączone).
-
-.TP
-.BI --conf " plik"
-Odczytuje konfigurację z
-.I pliku
-,którego każda linia odpowiada jednej opcji
-linii poleceń pozbawionej przedrostka '--'. Opcje podane w linii poleceń
-nadpisują opcje podane w pliku konfiguracyjnym.
-
-.TP
-.BI --pidfile " plik"
-Nazwa
-.I pliku
-z identyfikatorem procesu (domyślnie ./sgsnemu.pid)
-
-.TP
-.BI --statedir " ścieżka"
-.I Ścieżka
-do katalogu z trwałymi (nie ulotnymi) danymi (domyślnie ./)
-
-.TP
-.BI --dns " host"
-Serwer DNS wykorzystywany do zapytań APN.
-Jeśli parametr został pominięty, wykorzystywana jest domyślna, systemowa konfiguracja DNS.
-
-.TP
-.BI --listen " host"
-Lokalny adres IP, który zostanie użyty do nasłuchu przez interfejs Gn/Gp.
-Ta opcja musi zostać podana.
-Z przyczyn bezpieczeństwa nie może być wykorzystany INADDR_ANY.
-
-.TP
-.BI --remote " host"
-.I Host
-z węzłem GGSN wykorzystywanym do połączeń. Jeśli DNS jest prawidłowo skonfigurowany
-to powinno być możliwe podanie nazwy punktu dostępowego (APN) jako nazwy zdalnego hosta.
-
-.TP
-.BI --contexts " liczba"
-Liczba ustanawianych kontekstów (domyślnie = 1). W przypadku wielu kontekstó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ńczy wykonanie
-.b sgsnemu
-po upływie podanej liczy \fIsekund\fP.
-W przypadku wykorzystywania opcji ping można zakończyć
-.B sgsnemu
-po wyłaniu
-.B --pingcount
-pakietów.
-
-.TP
-.BI --gtpversion " wersja"
-.I wersja
-protokołu GTP wykorzystywana przy ustanawianiu kontekstów (domyślnie = 1).
-Jeśli nie jest możliwe ustanowienie kontekstu GTPw1
-.B sgsnemu
-powtórzy żądanie wykorzystując GTPw0.
-
-.TP
-.BI --apn " apn"
-.I apn
-wykorzystywany przy łączeniu się z węzłem GGSN (domyślnie = internet).
-APN jest akronimem angielskich słów Access Point Name.
-
-.TP
-.BI --selmode " tryb"
-Tryb wyboru wykorzystywany w komunikacji z węzłem GGSN (domyślnie = 0x01).
-Jako tryby wyboru mogą być wykorzystane następujące kody:
-0: MS lub sieć dostarczana przez APN, subskrypcja zweryfikowana,
-1: MS dostarczany przez APN, subskrypcja nie zweryfikowana,
-2: sieć dostarczana przez APN, subskrypcja nie zweryfikowana.
-
-.TP
-.BI --imsi " imsi"
-.I imsi
-wykorzystywane w komunikacji z węzłem GGSN (domyślnie = 240010123456789).
-IMSI jest akronimem angielskich słów International Mobile Subscriber Identity.
-IMSI musi składać się z dokładnie 15 cyfr. Porównaj z opcją
-.I contexts
-by zobaczyć wykorzystanie
-.I imsi
-w przypadku wielu kontekstów.
-
-.TP
-.BI --nsapi " nsapi"
-.I nsapi
-wykorzystywane w komunikacji z węzłem GGSN (domyślnie = 0).
-Wartość musi być pomiędzy 0, a 15.
-
-.TP
-.BI --msisdn " msisdn"
-.I msisdn
-wykorzystywane w komunikacji z węzłem GGSN (domyślnie = 46702123456).
-MSISDN jest akronimem angielskich słów International Mobile Integrated Services Digital Network.
-W istocie jest numerem telefonu zapisanym w międzynarodowym formacie bez wiodących 00 lub 011.
-Porównaj z opcją
-.I contexts
-by zobaczyć wykorzystanie
-.I msisdn
-w przypadku wielu kontekstów.
-
-.TP
-.BI --qos " qos"
-.I qos
-wykorzystywany w komunikacji z węzłem GGSN (domyślnie = 0x0b921f).
-QoS jest akronimem angielskich słów Quality of Service.
-Format tego parametru został określony na podstawie specyfikacji 3GPP 09.60.
-
-.TP
-.BI --charging " opłata"
-Charakterystyka rozliczania wykorzystywana w komunikacji z węzłem GGSN
-(domyślnie = 0x0800). 0x0800 = normalna, 0x0400 = przedpłata,
-0x0200 = płaska rata, 0x0100 = rozliczanie dynamiczne.
-Format pola został opisany w specyfikacji 3GPP 32.015.
-
-.TP
-.BI --uid " uid"
-Identyfikator użytkownika wysyłany do GGSN jako opcja konfiguracyjna protokołu.
-
-.TP
-.BI --pwd " hasło"
-Identyfikator wysyłane do GGSN jako opcja konfiguracyjna protokołu.
-
-.TP
-.BI --createif
-Tworzy lokalny interfejs tun, wykorzystywany dla
-przesyłania pakietów do i z interfejsu Gn/Gp.
-Należy zaznaczyć, że interfejs Gn/Gp zazwyczaj jest kierowany
-do Internetu przez GGSN. Tylko jeden interfejs może być utworzony, chociaż
-wiele kontekstów może zostać ustanowionych.
-Interfejs może być podany dla każdego kontekstu jako adres IP, lub może być
-określony za pomocą opcji
-.I net.
-
-.TP
-.BI --net " sieć"
-Adres sieci lokalnego interfejsu.
-Opcja
-.I net
-jest poprawna tylko wtedy, gdy została wykorzystana opcja
-.I createif.
-Wartość parametru
-.I net
-jest podawana w formacie cidr (sieć/maska). Jeśli opcja
-.I net
-zostanie pominięta, adres IP jest rezerwowany dla każdego ustanawianego kontekstu.
-
-.TP
-.BI --defaultroute
-Definiuje domyślne trasowanie przez lokalny interfejs tun.
-
-.TP
-.BI --ipup " skrypt"
-Skrypt wykonywany po aktywacji interfejsu Gi w sieci tun.
-Skrypt jest uruchamiany z następującymi parametrami <nazwa urządzenia> <adres ip>.
-
-.TP
-.BI --ipdown " skrypt"
-Skrypt wykonywany po wyłączeniu interfejsu Gi w sieci tun.
-Skrypt jest uruchamiany z następującymi parametrami <nazwa urządzenia> <adres ip>.
-
-.TP
-.BI --pinghost " host"
-Powoduje wysyłanie pakietów ICMP do urządzenia
-.I host
-poprzez interfejs Gn/Gp. Statystyki połączeń są raportowane w formie
-bardzo zbliżonej do wyjścia oryginalnego programu ping. Możesz wykorzystać
-to udogodnienie do testowania wydajności GGSN.
-
-.TP
-.BI --pingrate " liczba"
-Ilość żądań ICMP generowanych w przeciągu sekundy (domyślnie = 1).
-
-.TP
-.BI --pingsize " liczba"
-Rozmiar generowanych żądań ICMP wyrażony w oktetach (domyślnie = 56).
-
-
-.TP
-.BI --pingcount " liczba"
-Oczekiwana ilość wygenerowanych żądań ICMP (domyślnie = 0).
-Wartość 0 (zero) oznacza wielkość nieograniczoną.
-
-.TP
-.BI --pingquiet
-Wyłącza wypisywanie informacji o otrzymanych pakietach (domyślnie pakiety są wypisywane).
-Jest to całkiem przydatne dla dużych ilości pakietów ICMP generowanych w przeciągu sekundy
-(porównaj z opcją pingrate).
-
-.SH PLIKI
-.I sgsnemu.conf
-.RS
-Plik konfiguracyjny dla
-.B sgsnemu.
-.RE
-.I .sgsnemu.pid
-.RS
-Plik zawierający identyfikator procesu.
-.RE
-.I ./
-.RS
-Katalog przechowujący trwałe (nie ulotne) dane.
-.RE
-
-.SH BŁĘDY
-Zgłaszaj błędy na listę śledzenia błędów OpenGGSN
-.I http://sourceforge.net/projects/sgsnemu/
-
-
-.SH "ZOBACZ TAKŻE"
-.BR ggsn (8),
-.BR syslog (8)
-
-.SH UWAGI
-.LP
-
-Oprócz długich, udokumentowanych w tym podręczniku, opcji
-.B sgsnemu
-wspiera również pewną liczbą krótkich opcji o tej samej funkcjonalności.
-Wywołaj
-.B sgsnemu --help
-by uzyskać pełną listę dostępnych opcji.
-
-Sterownik TUN/TAP jest wymagany dla poprawnego działania
-.B sgsnemu.
-Dla jąder linuksa późniejszych niż 2.4.7 sterownik TUN/TAP jest zawarty w jądrze,
-chociaż w typowej sytuacji musi być ładowany oddzielnie za pomocą
-.B modprobe tun.
-Aby ładować automatycznie należy do pliku
-.B /etc/modules.conf.
-dodać linię
-.B alias char-major-10-200 tun
-Aby uzyskać informacje o innych platformach zobacz stronę
-.I http://vtun.sourceforge.net/tun/
-opisującą jak zainstalować i skonfigurować sterownik tun.
-
-.B ggsn
-wykorzystuje protokół tunelowania GPRS (GTP) wyspecyfikowany przez
-Third Generation Partnership Project (3GPP). Specyfikacje protokołów 3GPP
-mogą być znalezione na
-.I http://www.3gpp.org
-
-.SH COPYRIGHT
-
-Copyright (C) 2002, 2003, 2004 by Mondru AB.
-
-Zawartość tego pliku może być wykorzystywana stosownie do terminów
-Ogólnej, Publicznej Licencji (GPL) GNU w wersji 2 dostarczonej wraz
-z niniejszą uwagą o prawach autorskich zawartą we wszystkich kopiach
-i istotnych fragmentach oprogramowania.
-
-.SH AUTORZY
-Jens Jakobsen <jj@openggsn.org>
-
-.SH TŁUMACZENIE
-Polish translation copyright (C) 2004 Marek Żakowicz <mazaczek@users.sourceforge.net>
-
-Tłumaczenie jest chronione prawami autorskimi.
-Dozwolone jest korzystanie, rozprowadzanie i modyfikacja na zasadach licencji GNU GPL 2.
diff --git a/ggsn/Makefile.am b/ggsn/Makefile.am
index ada5720..91df8f0 100644
--- a/ggsn/Makefile.am
+++ b/ggsn/Makefile.am
@@ -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
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 0022b1b..3fd584a 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -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);
}
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7c06e27..590f0ec 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -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
diff --git a/lib/debug.c b/lib/debug.c
new file mode 100644
index 0000000..b3850f9
--- /dev/null
+++ b/lib/debug.c
@@ -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),
+};
diff --git a/lib/ippool.c b/lib/ippool.c
index 7ece1e8..1f79a77 100644
--- a/lib/ippool.c
+++ b/lib/ippool.c
@@ -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;
}
diff --git a/lib/syserr.c b/lib/syserr.c
deleted file mode 100644
index 73b3f15..0000000
--- a/lib/syserr.c
+++ /dev/null
@@ -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);
- }
-}
-
diff --git a/lib/syserr.h b/lib/syserr.h
index 991549c..0c50a5f 100644
--- a/lib/syserr.h
+++ b/lib/syserr.h
@@ -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 */
diff --git a/lib/tun.c b/lib/tun.c
index 43a02ee..94d92ef 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -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;
}
diff --git a/sgsnemu/Makefile.am b/sgsnemu/Makefile.am
index 8ce1b61..4d02eca 100644
--- a/sgsnemu/Makefile.am
+++ b/sgsnemu/Makefile.am
@@ -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
diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c
index 79494c9..5b56751 100644
--- a/sgsnemu/sgsnemu.c
+++ b/sgsnemu/sgsnemu.c
@@ -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");
}