socket: Add support for GRE sockets
diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am
index cc948fd..5abc4dd 100644
--- a/openbsc/include/openbsc/Makefile.am
+++ b/openbsc/include/openbsc/Makefile.am
@@ -6,7 +6,7 @@
 		 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 0000000..f2e264e
--- /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 3ed4d42..c72f6bc 100644
--- a/openbsc/src/socket.c
+++ b/openbsc/src/socket.c
@@ -48,8 +48,19 @@
 	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 @@
 	//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 @@
 
 	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");