mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-ggsn.git
synced 2025-11-03 05:33:23 +00:00
Changes to allow compilation under Solaris
This commit is contained in:
@@ -2,7 +2,7 @@ bin_PROGRAMS = ggsn
|
||||
|
||||
LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib @EXEC_LDFLAGS@
|
||||
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
|
||||
ggsn_SOURCES = ggsn.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ bin_PROGRAMS = ggsn
|
||||
|
||||
LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib @EXEC_LDFLAGS@
|
||||
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
|
||||
ggsn_SOURCES = ggsn.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c
|
||||
subdir = ggsn
|
||||
|
||||
43
ggsn/ggsn.c
43
ggsn/ggsn.c
@@ -36,19 +36,15 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <features.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <asm/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "tun.h"
|
||||
@@ -88,10 +84,38 @@ void log_pid(char *pidfile) {
|
||||
"Failed to create process ID file: %s!", pidfile);
|
||||
return;
|
||||
}
|
||||
fprintf(file, "%d\n", getpid());
|
||||
fprintf(file, "%d\n", (int) getpid());
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
#ifdef __sun__
|
||||
int daemon(int nochdir, int noclose) {
|
||||
int fd;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
return (-1);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
if (setsid() == -1)
|
||||
return (-1);
|
||||
|
||||
if (!nochdir) chdir("/");
|
||||
|
||||
if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
if (fd > 2) close (fd);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int encaps_printf(void *p, void *packet, unsigned len)
|
||||
{
|
||||
@@ -192,7 +216,14 @@ int main(int argc, char **argv)
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
if (cmdline_parser (argc, argv, &args_info) != 0)
|
||||
exit(1);
|
||||
|
||||
27
ggsn/tun.c
27
ggsn/tun.c
@@ -43,19 +43,24 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/if.h>
|
||||
#include <errno.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#elif defined (__sun__)
|
||||
#include <net/if_tun.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "tun.h"
|
||||
#include "syserr.h"
|
||||
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
|
||||
{
|
||||
int len = RTA_LENGTH(dlen);
|
||||
@@ -69,6 +74,7 @@ int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
|
||||
n->nlmsg_len = alen + len;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int tun_gifindex(struct tun_t *this, int *index) {
|
||||
struct ifreq ifr;
|
||||
@@ -118,7 +124,7 @@ int tun_sifflags(struct tun_t *this, int flags) {
|
||||
}
|
||||
|
||||
|
||||
/* Currently unused */
|
||||
/* Currently unused
|
||||
int tun_addroute2(struct tun_t *this,
|
||||
struct in_addr *dst,
|
||||
struct in_addr *gateway,
|
||||
@@ -208,16 +214,18 @@ int tun_addroute2(struct tun_t *this,
|
||||
req.n.nlmsg_seq = 0;
|
||||
req.n.nlmsg_flags |= NLM_F_ACK;
|
||||
|
||||
status = sendmsg(fd, &msg, 0); /* TODO: Error check */
|
||||
status = sendmsg(fd, &msg, 0); * TODO: Error check *
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
int tun_addaddr(struct tun_t *this,
|
||||
struct in_addr *addr,
|
||||
struct in_addr *dstaddr,
|
||||
struct in_addr *netmask) {
|
||||
|
||||
#ifdef __linux__
|
||||
struct {
|
||||
struct nlmsghdr n;
|
||||
struct ifaddrmsg i;
|
||||
@@ -232,10 +240,16 @@ int tun_addaddr(struct tun_t *this,
|
||||
struct sockaddr_nl nladdr;
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
#endif
|
||||
|
||||
if (!this->addrs) /* Use ioctl for first addr to make ping work */
|
||||
return tun_setaddr(this, addr, dstaddr, netmask);
|
||||
|
||||
#ifndef __linux__
|
||||
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
|
||||
"Setting multiple addresses only possible on linux");
|
||||
return -1;
|
||||
#else
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
|
||||
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
|
||||
@@ -315,6 +329,7 @@ int tun_addaddr(struct tun_t *this,
|
||||
close(fd);
|
||||
this->addrs++;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ bin_PROGRAMS = sgsnemu
|
||||
|
||||
LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib @EXEC_LDFLAGS@
|
||||
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
|
||||
sgsnemu_SOURCES = sgsnemu.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ bin_PROGRAMS = sgsnemu
|
||||
|
||||
LDFLAGS = -Wl,--rpath -Wl,/usr/local/lib @EXEC_LDFLAGS@
|
||||
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -ansi -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb -lgtp -L../gtp
|
||||
|
||||
sgsnemu_SOURCES = sgsnemu.c tun.c tun.h cmdline.c cmdline.h ippool.h ippool.c syserr.h syserr.c
|
||||
subdir = sgsnemu
|
||||
|
||||
@@ -43,11 +43,8 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <net/if.h>
|
||||
#include <features.h>
|
||||
#include <errno.h>
|
||||
#include <asm/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <resolv.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -122,22 +119,22 @@ struct {
|
||||
#define CREATEPING_ICMP 8
|
||||
|
||||
struct ip_ping {
|
||||
u_int8_t ipver; /* Type and header length*/
|
||||
u_int8_t tos; /* Type of Service */
|
||||
u_int16_t length; /* Total length */
|
||||
u_int16_t fragid; /* Identifier */
|
||||
u_int16_t offset; /* Flags and fragment offset */
|
||||
u_int8_t ttl; /* Time to live */
|
||||
u_int8_t protocol; /* Protocol */
|
||||
u_int16_t ipcheck; /* Header checksum */
|
||||
u_int32_t src; /* Source address */
|
||||
u_int32_t dst; /* Destination */
|
||||
u_int8_t type; /* Type and header length*/
|
||||
u_int8_t code; /* Code */
|
||||
u_int16_t checksum; /* Header checksum */
|
||||
u_int16_t ident; /* Identifier */
|
||||
u_int16_t seq; /* Sequence number */
|
||||
u_int8_t data[CREATEPING_MAX]; /* Data */
|
||||
uint8_t ipver; /* Type and header length*/
|
||||
uint8_t tos; /* Type of Service */
|
||||
uint16_t length; /* Total length */
|
||||
uint16_t fragid; /* Identifier */
|
||||
uint16_t offset; /* Flags and fragment offset */
|
||||
uint8_t ttl; /* Time to live */
|
||||
uint8_t protocol; /* Protocol */
|
||||
uint16_t ipcheck; /* Header checksum */
|
||||
uint32_t src; /* Source address */
|
||||
uint32_t dst; /* Destination */
|
||||
uint8_t type; /* Type and header length*/
|
||||
uint8_t code; /* Code */
|
||||
uint16_t checksum; /* Header checksum */
|
||||
uint16_t ident; /* Identifier */
|
||||
uint16_t seq; /* Sequence number */
|
||||
uint8_t data[CREATEPING_MAX]; /* Data */
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Statistical values for ping */
|
||||
@@ -205,7 +202,7 @@ void log_pid(char *pidfile) {
|
||||
umask(oldmask);
|
||||
if(!file)
|
||||
return;
|
||||
fprintf(file, "%d\n", getpid());
|
||||
fprintf(file, "%d\n", (int) getpid());
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
@@ -782,8 +779,8 @@ int create_ping(void *gsn, struct pdp_t *pdp,
|
||||
struct in_addr *dst, int seq, int datasize) {
|
||||
|
||||
struct ip_ping pack;
|
||||
u_int16_t *p = (u_int16_t *) &pack;
|
||||
u_int8_t *p8 = (u_int8_t *) &pack;
|
||||
uint16_t *p = (uint16_t *) &pack;
|
||||
uint8_t *p8 = (uint8_t *) &pack;
|
||||
struct in_addr src;
|
||||
int n;
|
||||
long int sum = 0;
|
||||
@@ -817,14 +814,14 @@ int create_ping(void *gsn, struct pdp_t *pdp,
|
||||
pack.seq = htons(seq);
|
||||
|
||||
/* Generate ICMP payload */
|
||||
p8 = (u_int8_t *) &pack + CREATEPING_IP + CREATEPING_ICMP;
|
||||
p8 = (uint8_t *) &pack + CREATEPING_IP + CREATEPING_ICMP;
|
||||
for (n=0; n<(datasize); n++) p8[n] = n;
|
||||
|
||||
if (datasize >= sizeof(struct timeval))
|
||||
gettimeofday(tp, &tz);
|
||||
|
||||
/* Calculate IP header checksum */
|
||||
p = (u_int16_t *) &pack;
|
||||
p = (uint16_t *) &pack;
|
||||
count = CREATEPING_IP;
|
||||
sum = 0;
|
||||
while (count>1) {
|
||||
@@ -839,7 +836,7 @@ int create_ping(void *gsn, struct pdp_t *pdp,
|
||||
/* Calculate ICMP checksum */
|
||||
count = CREATEPING_ICMP + datasize; /* Length of ICMP message */
|
||||
sum = 0;
|
||||
p = (u_int16_t *) &pack;
|
||||
p = (uint16_t *) &pack;
|
||||
p += CREATEPING_IP / 2;
|
||||
while (count>1) {
|
||||
sum += *p++;
|
||||
@@ -1012,7 +1009,14 @@ int main(int argc, char **argv)
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
/* Process options given in configuration file and command line */
|
||||
if (process_options(argc, argv))
|
||||
|
||||
@@ -43,19 +43,24 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/if.h>
|
||||
#include <errno.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#elif defined (__sun__)
|
||||
#include <net/if_tun.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "tun.h"
|
||||
#include "syserr.h"
|
||||
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
|
||||
{
|
||||
int len = RTA_LENGTH(dlen);
|
||||
@@ -69,6 +74,7 @@ int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
|
||||
n->nlmsg_len = alen + len;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int tun_gifindex(struct tun_t *this, int *index) {
|
||||
struct ifreq ifr;
|
||||
@@ -118,7 +124,7 @@ int tun_sifflags(struct tun_t *this, int flags) {
|
||||
}
|
||||
|
||||
|
||||
/* Currently unused */
|
||||
/* Currently unused
|
||||
int tun_addroute2(struct tun_t *this,
|
||||
struct in_addr *dst,
|
||||
struct in_addr *gateway,
|
||||
@@ -208,16 +214,18 @@ int tun_addroute2(struct tun_t *this,
|
||||
req.n.nlmsg_seq = 0;
|
||||
req.n.nlmsg_flags |= NLM_F_ACK;
|
||||
|
||||
status = sendmsg(fd, &msg, 0); /* TODO: Error check */
|
||||
status = sendmsg(fd, &msg, 0); * TODO: Error check *
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
int tun_addaddr(struct tun_t *this,
|
||||
struct in_addr *addr,
|
||||
struct in_addr *dstaddr,
|
||||
struct in_addr *netmask) {
|
||||
|
||||
#ifdef __linux__
|
||||
struct {
|
||||
struct nlmsghdr n;
|
||||
struct ifaddrmsg i;
|
||||
@@ -232,10 +240,16 @@ int tun_addaddr(struct tun_t *this,
|
||||
struct sockaddr_nl nladdr;
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
#endif
|
||||
|
||||
if (!this->addrs) /* Use ioctl for first addr to make ping work */
|
||||
return tun_setaddr(this, addr, dstaddr, netmask);
|
||||
|
||||
#ifndef __linux__
|
||||
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
|
||||
"Setting multiple addresses only possible on linux");
|
||||
return -1;
|
||||
#else
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
|
||||
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
|
||||
@@ -315,6 +329,7 @@ int tun_addaddr(struct tun_t *this,
|
||||
close(fd);
|
||||
this->addrs++;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user