blob: af216f7735afeb40d9f33c56690da9dd1a652100 [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;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +010052 t->flags |= GTP_TUN_IFNS;
Andreas Schultz49773302016-04-11 16:09:56 +020053}
54EXPORT_SYMBOL(gtp_tunnel_set_ifns);
55
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010056void gtp_tunnel_set_ifidx(struct gtp_tunnel *t, uint32_t ifidx)
57{
58 t->ifidx = ifidx;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +010059 t->flags |= GTP_TUN_IFIDX;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010060}
61EXPORT_SYMBOL(gtp_tunnel_set_ifidx);
62
Pablo Neira Ayusoed42b8a2024-01-31 19:03:13 +010063void gtp_tunnel_set_family(struct gtp_tunnel *t, uint16_t family)
64{
65 t->ms_addr.family = family;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +010066 t->flags |= GTP_TUN_FAMILY;
Pablo Neira Ayusoed42b8a2024-01-31 19:03:13 +010067}
68EXPORT_SYMBOL(gtp_tunnel_set_family);
69
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010070void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr)
71{
Oliver Smith717db092023-10-18 15:16:12 +020072 t->ms_addr.family = AF_INET;
73 t->ms_addr.ip4 = *ms_addr;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +010074 t->flags |= GTP_TUN_FAMILY | GTP_TUN_MS_ADDR;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010075}
76EXPORT_SYMBOL(gtp_tunnel_set_ms_ip4);
77
78void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr)
79{
Oliver Smith717db092023-10-18 15:16:12 +020080 t->sgsn_addr.family = AF_INET;
81 t->sgsn_addr.ip4 = *sgsn_addr;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +010082 t->flags |= GTP_TUN_SGSN_ADDR;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010083}
84EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip4);
85
Oliver Smitha2956152023-10-19 14:11:19 +020086void gtp_tunnel_set_ms_ip6(struct gtp_tunnel *t, const struct in6_addr *ms_addr)
87{
88 t->ms_addr.family = AF_INET6;
89 t->ms_addr.ip6 = *ms_addr;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +010090 t->flags |= GTP_TUN_FAMILY | GTP_TUN_MS_ADDR;
Oliver Smitha2956152023-10-19 14:11:19 +020091}
92EXPORT_SYMBOL(gtp_tunnel_set_ms_ip6);
93
94void gtp_tunnel_set_sgsn_ip6(struct gtp_tunnel *t, const struct in6_addr *sgsn_addr)
95{
96 t->sgsn_addr.family = AF_INET6;
97 t->sgsn_addr.ip6 = *sgsn_addr;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +010098 t->flags |= GTP_TUN_SGSN_ADDR;
Oliver Smitha2956152023-10-19 14:11:19 +020099}
100EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip6);
101
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100102void gtp_tunnel_set_version(struct gtp_tunnel *t, uint32_t version)
103{
104 t->gtp_version = version;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +0100105 t->flags |= GTP_TUN_VERSION;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100106}
107EXPORT_SYMBOL(gtp_tunnel_set_version);
108
109void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid)
110{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200111 t->u.v0.tid = tid;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +0100112 t->flags |= GTP_TUN_V0_TID;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100113}
114EXPORT_SYMBOL(gtp_tunnel_set_tid);
115
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100116void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid)
117{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200118 t->u.v0.flowid = flowid;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +0100119 t->flags |= GTP_TUN_V0_FLOWID;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100120}
121EXPORT_SYMBOL(gtp_tunnel_set_flowid);
122
Andreas Schultz17c816f2016-04-11 16:10:03 +0200123void gtp_tunnel_set_i_tei(struct gtp_tunnel *t, uint32_t i_tei)
124{
125 t->u.v1.i_tei = i_tei;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +0100126 t->flags |= GTP_TUN_V1_I_TEI;
Andreas Schultz17c816f2016-04-11 16:10:03 +0200127}
128EXPORT_SYMBOL(gtp_tunnel_set_i_tei);
129
130void gtp_tunnel_set_o_tei(struct gtp_tunnel *t, uint32_t o_tei)
131{
132 t->u.v1.o_tei = o_tei;
Pablo Neira Ayuso6f1c38f2024-01-31 13:40:35 +0100133 t->flags |= GTP_TUN_V1_O_TEI;
Andreas Schultz17c816f2016-04-11 16:10:03 +0200134}
135EXPORT_SYMBOL(gtp_tunnel_set_o_tei);
136
Andreas Schultz49773302016-04-11 16:09:56 +0200137const int gtp_tunnel_get_ifns(struct gtp_tunnel *t)
138{
139 return t->ifns;
140}
141EXPORT_SYMBOL(gtp_tunnel_get_ifns);
142
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100143const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t)
144{
145 return t->ifidx;
146}
147EXPORT_SYMBOL(gtp_tunnel_get_ifidx);
148
149const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t)
150{
Oliver Smith717db092023-10-18 15:16:12 +0200151 return &t->ms_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100152}
153EXPORT_SYMBOL(gtp_tunnel_get_ms_ip4);
154
155const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t)
156{
Oliver Smith717db092023-10-18 15:16:12 +0200157 return &t->sgsn_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100158}
159EXPORT_SYMBOL(gtp_tunnel_get_sgsn_ip4);
160
161int gtp_tunnel_get_version(struct gtp_tunnel *t)
162{
163 return t->gtp_version;
164}
165EXPORT_SYMBOL(gtp_tunnel_get_version);
166
167uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t)
168{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200169 return t->u.v0.tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100170}
171EXPORT_SYMBOL(gtp_tunnel_get_tid);
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100172
173uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t)
174{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200175 return t->u.v0.flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100176}
177EXPORT_SYMBOL(gtp_tunnel_get_flowid);
Andreas Schultz17c816f2016-04-11 16:10:03 +0200178
179uint32_t gtp_tunnel_get_i_tei(struct gtp_tunnel *t)
180{
181 return t->u.v1.i_tei;
182}
183EXPORT_SYMBOL(gtp_tunnel_get_i_tei);
184
185uint32_t gtp_tunnel_get_o_tei(struct gtp_tunnel *t)
186{
187 return t->u.v1.o_tei;
188}
189EXPORT_SYMBOL(gtp_tunnel_get_o_tei);