diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-05-19 14:11:05 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-05-19 14:11:38 +0200 |
commit | 3a318ab9716718a39a6907d012b6f616fe46823d (patch) | |
tree | 951b93a4c0f7f248ae5888adc8dff4e54f746662 | |
parent | 7af4962e071a69a48231abede1701ca65cb620fe (diff) |
socket: Add support for GRE sockets
-rw-r--r-- | openbsc/include/openbsc/Makefile.am | 2 | ||||
-rw-r--r-- | openbsc/include/openbsc/socket.h | 14 | ||||
-rw-r--r-- | openbsc/src/socket.c | 19 |
3 files changed, 30 insertions, 5 deletions
diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am index cc948fd95..5abc4ddd0 100644 --- a/openbsc/include/openbsc/Makefile.am +++ b/openbsc/include/openbsc/Makefile.am @@ -6,7 +6,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \ bsc_rll.h mncc.h transaction.h ussd.h gsm_04_80.h \ silent_call.h mgcp.h meas_rep.h rest_octets.h \ system_information.h handover.h mgcp_internal.h \ - vty.h \ + vty.h socket.h \ crc24.h gprs_bssgp.h gprs_llc.h gprs_ns.h gprs_gmm.h \ gb_proxy.h gprs_sgsn.h gsm_04_08_gprs.h sgsn.h diff --git a/openbsc/include/openbsc/socket.h b/openbsc/include/openbsc/socket.h new file mode 100644 index 000000000..f2e264ea6 --- /dev/null +++ b/openbsc/include/openbsc/socket.h @@ -0,0 +1,14 @@ +#ifndef _BSC_SOCKET_H +#define _BSC_SOCKET_H + +#include <sys/types.h> +#include <osmocore/select.h> + +#ifndef IPPROTO_GRE +#define IPPROTO_GRE 47 +#endif + +int make_sock(struct bsc_fd *bfd, int proto, u_int16_t port, + int (*cb)(struct bsc_fd *fd, unsigned int what)); + +#endif /* _BSC_SOCKET_H */ diff --git a/openbsc/src/socket.c b/openbsc/src/socket.c index 3ed4d425a..c72f6bc27 100644 --- a/openbsc/src/socket.c +++ b/openbsc/src/socket.c @@ -48,8 +48,19 @@ int make_sock(struct bsc_fd *bfd, int proto, u_int16_t port, int ret, on = 1; int type = SOCK_STREAM; - if (proto == IPPROTO_UDP) + switch (proto) { + case IPPROTO_TCP: + type = SOCK_STREAM; + break; + case IPPROTO_UDP: type = SOCK_DGRAM; + break; + case IPPROTO_GRE: + type = SOCK_RAW; + break; + default: + return -EINVAL; + } bfd->fd = socket(AF_INET, type, proto); bfd->cb = cb; @@ -57,7 +68,7 @@ int make_sock(struct bsc_fd *bfd, int proto, u_int16_t port, //bfd->data = line; if (bfd->fd < 0) { - LOGP(DINP, LOGL_ERROR, "could not create TCP socket.\n"); + LOGP(DINP, LOGL_ERROR, "could not create socket.\n"); return -EIO; } @@ -70,13 +81,13 @@ int make_sock(struct bsc_fd *bfd, int proto, u_int16_t port, ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr)); if (ret < 0) { - LOGP(DINP, LOGL_ERROR, "could not bind l2 socket %s\n", + LOGP(DINP, LOGL_ERROR, "could not bind socket %s\n", strerror(errno)); close(bfd->fd); return -EIO; } - if (proto != IPPROTO_UDP) { + if (proto == IPPROTO_TCP) { ret = listen(bfd->fd, 1); if (ret < 0) { perror("listen"); |