blob: bcc3e745ec30b8309343563e58ab714994c4a39e [file] [log] [blame]
Harald Welte51b00a62014-04-03 09:37:38 -04001/* External interface functions of the library */
2
3/* (C) 2014 by sysmocom - s.f.m.c. GmbH
4 * Author: Pablo Neira Ayuso <pablo@gnumonks.org>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010023#include <stdlib.h>
24#include <netinet/in.h>
25
26#include <libgtpnl/gtp.h>
27
28#include "internal.h"
29
30struct gtp_tunnel *gtp_tunnel_alloc(void)
31{
Pablo Neira Ayusoee7bb1f2016-05-08 18:22:54 +020032 struct gtp_tunnel *t;
33
34 t = calloc(1, sizeof(struct gtp_tunnel));
35 if (!t)
36 return NULL;
37
38 t->ifns = -1;
39 return t;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010040}
41EXPORT_SYMBOL(gtp_tunnel_alloc);
42
43void gtp_tunnel_free(struct gtp_tunnel *t)
44{
45 free(t);
46}
47EXPORT_SYMBOL(gtp_tunnel_free);
48
Andreas Schultz49773302016-04-11 16:09:56 +020049void gtp_tunnel_set_ifns(struct gtp_tunnel *t, int ifns)
50{
51 t->ifns = ifns;
52}
53EXPORT_SYMBOL(gtp_tunnel_set_ifns);
54
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010055void gtp_tunnel_set_ifidx(struct gtp_tunnel *t, uint32_t ifidx)
56{
57 t->ifidx = ifidx;
58}
59EXPORT_SYMBOL(gtp_tunnel_set_ifidx);
60
61void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr)
62{
63 t->ms_addr = *ms_addr;
64}
65EXPORT_SYMBOL(gtp_tunnel_set_ms_ip4);
66
67void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr)
68{
69 t->sgsn_addr = *sgsn_addr;
70}
71EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip4);
72
73void gtp_tunnel_set_version(struct gtp_tunnel *t, uint32_t version)
74{
75 t->gtp_version = version;
76}
77EXPORT_SYMBOL(gtp_tunnel_set_version);
78
79void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid)
80{
Andreas Schultz17c816f2016-04-11 16:10:03 +020081 t->u.v0.tid = tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010082}
83EXPORT_SYMBOL(gtp_tunnel_set_tid);
84
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +010085void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid)
86{
Andreas Schultz17c816f2016-04-11 16:10:03 +020087 t->u.v0.flowid = flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +010088}
89EXPORT_SYMBOL(gtp_tunnel_set_flowid);
90
Andreas Schultz17c816f2016-04-11 16:10:03 +020091void gtp_tunnel_set_i_tei(struct gtp_tunnel *t, uint32_t i_tei)
92{
93 t->u.v1.i_tei = i_tei;
94}
95EXPORT_SYMBOL(gtp_tunnel_set_i_tei);
96
97void gtp_tunnel_set_o_tei(struct gtp_tunnel *t, uint32_t o_tei)
98{
99 t->u.v1.o_tei = o_tei;
100}
101EXPORT_SYMBOL(gtp_tunnel_set_o_tei);
102
Andreas Schultz49773302016-04-11 16:09:56 +0200103const int gtp_tunnel_get_ifns(struct gtp_tunnel *t)
104{
105 return t->ifns;
106}
107EXPORT_SYMBOL(gtp_tunnel_get_ifns);
108
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100109const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t)
110{
111 return t->ifidx;
112}
113EXPORT_SYMBOL(gtp_tunnel_get_ifidx);
114
115const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t)
116{
117 return &t->ms_addr;
118}
119EXPORT_SYMBOL(gtp_tunnel_get_ms_ip4);
120
121const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t)
122{
123 return &t->sgsn_addr;
124}
125EXPORT_SYMBOL(gtp_tunnel_get_sgsn_ip4);
126
127int gtp_tunnel_get_version(struct gtp_tunnel *t)
128{
129 return t->gtp_version;
130}
131EXPORT_SYMBOL(gtp_tunnel_get_version);
132
133uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t)
134{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200135 return t->u.v0.tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100136}
137EXPORT_SYMBOL(gtp_tunnel_get_tid);
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100138
139uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t)
140{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200141 return t->u.v0.flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100142}
143EXPORT_SYMBOL(gtp_tunnel_get_flowid);
Andreas Schultz17c816f2016-04-11 16:10:03 +0200144
145uint32_t gtp_tunnel_get_i_tei(struct gtp_tunnel *t)
146{
147 return t->u.v1.i_tei;
148}
149EXPORT_SYMBOL(gtp_tunnel_get_i_tei);
150
151uint32_t gtp_tunnel_get_o_tei(struct gtp_tunnel *t)
152{
153 return t->u.v1.o_tei;
154}
155EXPORT_SYMBOL(gtp_tunnel_get_o_tei);