blob: 657eb7a3833ed0e43ba6df8cb2f2fc4ef1ac7ace [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
Harald Welted2bb0bc2016-07-28 20:34:45 +02009 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
Harald Welte51b00a62014-04-03 09:37:38 -040012 *
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
Harald Welted2bb0bc2016-07-28 20:34:45 +020016 * GNU Lesser General Public License for more details.
Harald Welte51b00a62014-04-03 09:37:38 -040017 *
Harald Welted2bb0bc2016-07-28 20:34:45 +020018 * You should have received a copy of the GNU Lesser General Public License
Harald Welte51b00a62014-04-03 09:37:38 -040019 * 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{
Oliver Smith717db092023-10-18 15:16:12 +020063 t->ms_addr.family = AF_INET;
64 t->ms_addr.ip4 = *ms_addr;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010065}
66EXPORT_SYMBOL(gtp_tunnel_set_ms_ip4);
67
68void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr)
69{
Oliver Smith717db092023-10-18 15:16:12 +020070 t->sgsn_addr.family = AF_INET;
71 t->sgsn_addr.ip4 = *sgsn_addr;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010072}
73EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip4);
74
Oliver Smitha2956152023-10-19 14:11:19 +020075void gtp_tunnel_set_ms_ip6(struct gtp_tunnel *t, const struct in6_addr *ms_addr)
76{
77 t->ms_addr.family = AF_INET6;
78 t->ms_addr.ip6 = *ms_addr;
79}
80EXPORT_SYMBOL(gtp_tunnel_set_ms_ip6);
81
82void gtp_tunnel_set_sgsn_ip6(struct gtp_tunnel *t, const struct in6_addr *sgsn_addr)
83{
84 t->sgsn_addr.family = AF_INET6;
85 t->sgsn_addr.ip6 = *sgsn_addr;
86}
87EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip6);
88
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010089void gtp_tunnel_set_version(struct gtp_tunnel *t, uint32_t version)
90{
91 t->gtp_version = version;
92}
93EXPORT_SYMBOL(gtp_tunnel_set_version);
94
95void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid)
96{
Andreas Schultz17c816f2016-04-11 16:10:03 +020097 t->u.v0.tid = tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010098}
99EXPORT_SYMBOL(gtp_tunnel_set_tid);
100
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100101void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid)
102{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200103 t->u.v0.flowid = flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100104}
105EXPORT_SYMBOL(gtp_tunnel_set_flowid);
106
Andreas Schultz17c816f2016-04-11 16:10:03 +0200107void gtp_tunnel_set_i_tei(struct gtp_tunnel *t, uint32_t i_tei)
108{
109 t->u.v1.i_tei = i_tei;
110}
111EXPORT_SYMBOL(gtp_tunnel_set_i_tei);
112
113void gtp_tunnel_set_o_tei(struct gtp_tunnel *t, uint32_t o_tei)
114{
115 t->u.v1.o_tei = o_tei;
116}
117EXPORT_SYMBOL(gtp_tunnel_set_o_tei);
118
Andreas Schultz49773302016-04-11 16:09:56 +0200119const int gtp_tunnel_get_ifns(struct gtp_tunnel *t)
120{
121 return t->ifns;
122}
123EXPORT_SYMBOL(gtp_tunnel_get_ifns);
124
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100125const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t)
126{
127 return t->ifidx;
128}
129EXPORT_SYMBOL(gtp_tunnel_get_ifidx);
130
131const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t)
132{
Oliver Smith717db092023-10-18 15:16:12 +0200133 return &t->ms_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100134}
135EXPORT_SYMBOL(gtp_tunnel_get_ms_ip4);
136
137const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t)
138{
Oliver Smith717db092023-10-18 15:16:12 +0200139 return &t->sgsn_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100140}
141EXPORT_SYMBOL(gtp_tunnel_get_sgsn_ip4);
142
143int gtp_tunnel_get_version(struct gtp_tunnel *t)
144{
145 return t->gtp_version;
146}
147EXPORT_SYMBOL(gtp_tunnel_get_version);
148
149uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t)
150{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200151 return t->u.v0.tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100152}
153EXPORT_SYMBOL(gtp_tunnel_get_tid);
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100154
155uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t)
156{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200157 return t->u.v0.flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100158}
159EXPORT_SYMBOL(gtp_tunnel_get_flowid);
Andreas Schultz17c816f2016-04-11 16:10:03 +0200160
161uint32_t gtp_tunnel_get_i_tei(struct gtp_tunnel *t)
162{
163 return t->u.v1.i_tei;
164}
165EXPORT_SYMBOL(gtp_tunnel_get_i_tei);
166
167uint32_t gtp_tunnel_get_o_tei(struct gtp_tunnel *t)
168{
169 return t->u.v1.o_tei;
170}
171EXPORT_SYMBOL(gtp_tunnel_get_o_tei);