blob: 0c378c407436634eef342d0894949ca335d1805d [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
Pablo Neira Ayuso67e1fef2024-01-31 19:03:13 +010061void gtp_tunnel_set_family(struct gtp_tunnel *t, uint16_t family)
62{
63 t->ms_addr.family = family;
64}
65EXPORT_SYMBOL(gtp_tunnel_set_family);
66
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010067void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr)
68{
Oliver Smith717db092023-10-18 15:16:12 +020069 t->ms_addr.family = AF_INET;
70 t->ms_addr.ip4 = *ms_addr;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010071}
72EXPORT_SYMBOL(gtp_tunnel_set_ms_ip4);
73
74void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr)
75{
Oliver Smith717db092023-10-18 15:16:12 +020076 t->sgsn_addr.family = AF_INET;
77 t->sgsn_addr.ip4 = *sgsn_addr;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010078}
79EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip4);
80
Oliver Smitha2956152023-10-19 14:11:19 +020081void gtp_tunnel_set_ms_ip6(struct gtp_tunnel *t, const struct in6_addr *ms_addr)
82{
83 t->ms_addr.family = AF_INET6;
84 t->ms_addr.ip6 = *ms_addr;
85}
86EXPORT_SYMBOL(gtp_tunnel_set_ms_ip6);
87
88void gtp_tunnel_set_sgsn_ip6(struct gtp_tunnel *t, const struct in6_addr *sgsn_addr)
89{
90 t->sgsn_addr.family = AF_INET6;
91 t->sgsn_addr.ip6 = *sgsn_addr;
92}
93EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip6);
94
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010095void gtp_tunnel_set_version(struct gtp_tunnel *t, uint32_t version)
96{
97 t->gtp_version = version;
98}
99EXPORT_SYMBOL(gtp_tunnel_set_version);
100
101void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid)
102{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200103 t->u.v0.tid = tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100104}
105EXPORT_SYMBOL(gtp_tunnel_set_tid);
106
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100107void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid)
108{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200109 t->u.v0.flowid = flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100110}
111EXPORT_SYMBOL(gtp_tunnel_set_flowid);
112
Andreas Schultz17c816f2016-04-11 16:10:03 +0200113void gtp_tunnel_set_i_tei(struct gtp_tunnel *t, uint32_t i_tei)
114{
115 t->u.v1.i_tei = i_tei;
116}
117EXPORT_SYMBOL(gtp_tunnel_set_i_tei);
118
119void gtp_tunnel_set_o_tei(struct gtp_tunnel *t, uint32_t o_tei)
120{
121 t->u.v1.o_tei = o_tei;
122}
123EXPORT_SYMBOL(gtp_tunnel_set_o_tei);
124
Andreas Schultz49773302016-04-11 16:09:56 +0200125const int gtp_tunnel_get_ifns(struct gtp_tunnel *t)
126{
127 return t->ifns;
128}
129EXPORT_SYMBOL(gtp_tunnel_get_ifns);
130
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100131const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t)
132{
133 return t->ifidx;
134}
135EXPORT_SYMBOL(gtp_tunnel_get_ifidx);
136
137const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t)
138{
Oliver Smith717db092023-10-18 15:16:12 +0200139 return &t->ms_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100140}
141EXPORT_SYMBOL(gtp_tunnel_get_ms_ip4);
142
143const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t)
144{
Oliver Smith717db092023-10-18 15:16:12 +0200145 return &t->sgsn_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100146}
147EXPORT_SYMBOL(gtp_tunnel_get_sgsn_ip4);
148
149int gtp_tunnel_get_version(struct gtp_tunnel *t)
150{
151 return t->gtp_version;
152}
153EXPORT_SYMBOL(gtp_tunnel_get_version);
154
155uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t)
156{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200157 return t->u.v0.tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100158}
159EXPORT_SYMBOL(gtp_tunnel_get_tid);
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100160
161uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t)
162{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200163 return t->u.v0.flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100164}
165EXPORT_SYMBOL(gtp_tunnel_get_flowid);
Andreas Schultz17c816f2016-04-11 16:10:03 +0200166
167uint32_t gtp_tunnel_get_i_tei(struct gtp_tunnel *t)
168{
169 return t->u.v1.i_tei;
170}
171EXPORT_SYMBOL(gtp_tunnel_get_i_tei);
172
173uint32_t gtp_tunnel_get_o_tei(struct gtp_tunnel *t)
174{
175 return t->u.v1.o_tei;
176}
177EXPORT_SYMBOL(gtp_tunnel_get_o_tei);