blob: 4eadc29f7435384ee96153ed6b33b3d1035b5418 [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
75void gtp_tunnel_set_version(struct gtp_tunnel *t, uint32_t version)
76{
77 t->gtp_version = version;
78}
79EXPORT_SYMBOL(gtp_tunnel_set_version);
80
81void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid)
82{
Andreas Schultz17c816f2016-04-11 16:10:03 +020083 t->u.v0.tid = tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +010084}
85EXPORT_SYMBOL(gtp_tunnel_set_tid);
86
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +010087void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid)
88{
Andreas Schultz17c816f2016-04-11 16:10:03 +020089 t->u.v0.flowid = flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +010090}
91EXPORT_SYMBOL(gtp_tunnel_set_flowid);
92
Andreas Schultz17c816f2016-04-11 16:10:03 +020093void gtp_tunnel_set_i_tei(struct gtp_tunnel *t, uint32_t i_tei)
94{
95 t->u.v1.i_tei = i_tei;
96}
97EXPORT_SYMBOL(gtp_tunnel_set_i_tei);
98
99void gtp_tunnel_set_o_tei(struct gtp_tunnel *t, uint32_t o_tei)
100{
101 t->u.v1.o_tei = o_tei;
102}
103EXPORT_SYMBOL(gtp_tunnel_set_o_tei);
104
Andreas Schultz49773302016-04-11 16:09:56 +0200105const int gtp_tunnel_get_ifns(struct gtp_tunnel *t)
106{
107 return t->ifns;
108}
109EXPORT_SYMBOL(gtp_tunnel_get_ifns);
110
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100111const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t)
112{
113 return t->ifidx;
114}
115EXPORT_SYMBOL(gtp_tunnel_get_ifidx);
116
117const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t)
118{
Oliver Smith717db092023-10-18 15:16:12 +0200119 return &t->ms_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100120}
121EXPORT_SYMBOL(gtp_tunnel_get_ms_ip4);
122
123const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t)
124{
Oliver Smith717db092023-10-18 15:16:12 +0200125 return &t->sgsn_addr.ip4;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100126}
127EXPORT_SYMBOL(gtp_tunnel_get_sgsn_ip4);
128
129int gtp_tunnel_get_version(struct gtp_tunnel *t)
130{
131 return t->gtp_version;
132}
133EXPORT_SYMBOL(gtp_tunnel_get_version);
134
135uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t)
136{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200137 return t->u.v0.tid;
Pablo Neira Ayuso18532952014-02-22 22:09:59 +0100138}
139EXPORT_SYMBOL(gtp_tunnel_get_tid);
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100140
141uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t)
142{
Andreas Schultz17c816f2016-04-11 16:10:03 +0200143 return t->u.v0.flowid;
Pablo Neira Ayusob976ffa2014-03-20 13:56:55 +0100144}
145EXPORT_SYMBOL(gtp_tunnel_get_flowid);
Andreas Schultz17c816f2016-04-11 16:10:03 +0200146
147uint32_t gtp_tunnel_get_i_tei(struct gtp_tunnel *t)
148{
149 return t->u.v1.i_tei;
150}
151EXPORT_SYMBOL(gtp_tunnel_get_i_tei);
152
153uint32_t gtp_tunnel_get_o_tei(struct gtp_tunnel *t)
154{
155 return t->u.v1.o_tei;
156}
157EXPORT_SYMBOL(gtp_tunnel_get_o_tei);