Harald Welte | 51b00a6 | 2014-04-03 09:37:38 -0400 | [diff] [blame] | 1 | /* 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 Welte | d2bb0bc | 2016-07-28 20:34:45 +0200 | [diff] [blame] | 9 | * 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 Welte | 51b00a6 | 2014-04-03 09:37:38 -0400 | [diff] [blame] | 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 |
Harald Welte | d2bb0bc | 2016-07-28 20:34:45 +0200 | [diff] [blame] | 16 | * GNU Lesser General Public License for more details. |
Harald Welte | 51b00a6 | 2014-04-03 09:37:38 -0400 | [diff] [blame] | 17 | * |
Harald Welte | d2bb0bc | 2016-07-28 20:34:45 +0200 | [diff] [blame] | 18 | * You should have received a copy of the GNU Lesser General Public License |
Harald Welte | 51b00a6 | 2014-04-03 09:37:38 -0400 | [diff] [blame] | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
Pablo Neira Ayuso | 1853295 | 2014-02-22 22:09:59 +0100 | [diff] [blame] | 23 | #include <stdlib.h> |
| 24 | #include <netinet/in.h> |
| 25 | |
| 26 | #include <libgtpnl/gtp.h> |
| 27 | |
| 28 | #include "internal.h" |
| 29 | |
| 30 | struct gtp_tunnel *gtp_tunnel_alloc(void) |
| 31 | { |
Pablo Neira Ayuso | ee7bb1f | 2016-05-08 18:22:54 +0200 | [diff] [blame] | 32 | 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 Ayuso | 1853295 | 2014-02-22 22:09:59 +0100 | [diff] [blame] | 40 | } |
| 41 | EXPORT_SYMBOL(gtp_tunnel_alloc); |
| 42 | |
| 43 | void gtp_tunnel_free(struct gtp_tunnel *t) |
| 44 | { |
| 45 | free(t); |
| 46 | } |
| 47 | EXPORT_SYMBOL(gtp_tunnel_free); |
| 48 | |
Andreas Schultz | 4977330 | 2016-04-11 16:09:56 +0200 | [diff] [blame] | 49 | void gtp_tunnel_set_ifns(struct gtp_tunnel *t, int ifns) |
| 50 | { |
| 51 | t->ifns = ifns; |
| 52 | } |
| 53 | EXPORT_SYMBOL(gtp_tunnel_set_ifns); |
| 54 | |
Pablo Neira Ayuso | 1853295 | 2014-02-22 22:09:59 +0100 | [diff] [blame] | 55 | void gtp_tunnel_set_ifidx(struct gtp_tunnel *t, uint32_t ifidx) |
| 56 | { |
| 57 | t->ifidx = ifidx; |
| 58 | } |
| 59 | EXPORT_SYMBOL(gtp_tunnel_set_ifidx); |
| 60 | |
| 61 | void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr) |
| 62 | { |
| 63 | t->ms_addr = *ms_addr; |
| 64 | } |
| 65 | EXPORT_SYMBOL(gtp_tunnel_set_ms_ip4); |
| 66 | |
| 67 | void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr) |
| 68 | { |
| 69 | t->sgsn_addr = *sgsn_addr; |
| 70 | } |
| 71 | EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip4); |
| 72 | |
| 73 | void gtp_tunnel_set_version(struct gtp_tunnel *t, uint32_t version) |
| 74 | { |
| 75 | t->gtp_version = version; |
| 76 | } |
| 77 | EXPORT_SYMBOL(gtp_tunnel_set_version); |
| 78 | |
| 79 | void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid) |
| 80 | { |
Andreas Schultz | 17c816f | 2016-04-11 16:10:03 +0200 | [diff] [blame] | 81 | t->u.v0.tid = tid; |
Pablo Neira Ayuso | 1853295 | 2014-02-22 22:09:59 +0100 | [diff] [blame] | 82 | } |
| 83 | EXPORT_SYMBOL(gtp_tunnel_set_tid); |
| 84 | |
Pablo Neira Ayuso | b976ffa | 2014-03-20 13:56:55 +0100 | [diff] [blame] | 85 | void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid) |
| 86 | { |
Andreas Schultz | 17c816f | 2016-04-11 16:10:03 +0200 | [diff] [blame] | 87 | t->u.v0.flowid = flowid; |
Pablo Neira Ayuso | b976ffa | 2014-03-20 13:56:55 +0100 | [diff] [blame] | 88 | } |
| 89 | EXPORT_SYMBOL(gtp_tunnel_set_flowid); |
| 90 | |
Andreas Schultz | 17c816f | 2016-04-11 16:10:03 +0200 | [diff] [blame] | 91 | void gtp_tunnel_set_i_tei(struct gtp_tunnel *t, uint32_t i_tei) |
| 92 | { |
| 93 | t->u.v1.i_tei = i_tei; |
| 94 | } |
| 95 | EXPORT_SYMBOL(gtp_tunnel_set_i_tei); |
| 96 | |
| 97 | void gtp_tunnel_set_o_tei(struct gtp_tunnel *t, uint32_t o_tei) |
| 98 | { |
| 99 | t->u.v1.o_tei = o_tei; |
| 100 | } |
| 101 | EXPORT_SYMBOL(gtp_tunnel_set_o_tei); |
| 102 | |
Andreas Schultz | 4977330 | 2016-04-11 16:09:56 +0200 | [diff] [blame] | 103 | const int gtp_tunnel_get_ifns(struct gtp_tunnel *t) |
| 104 | { |
| 105 | return t->ifns; |
| 106 | } |
| 107 | EXPORT_SYMBOL(gtp_tunnel_get_ifns); |
| 108 | |
Pablo Neira Ayuso | 1853295 | 2014-02-22 22:09:59 +0100 | [diff] [blame] | 109 | const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t) |
| 110 | { |
| 111 | return t->ifidx; |
| 112 | } |
| 113 | EXPORT_SYMBOL(gtp_tunnel_get_ifidx); |
| 114 | |
| 115 | const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t) |
| 116 | { |
| 117 | return &t->ms_addr; |
| 118 | } |
| 119 | EXPORT_SYMBOL(gtp_tunnel_get_ms_ip4); |
| 120 | |
| 121 | const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t) |
| 122 | { |
| 123 | return &t->sgsn_addr; |
| 124 | } |
| 125 | EXPORT_SYMBOL(gtp_tunnel_get_sgsn_ip4); |
| 126 | |
| 127 | int gtp_tunnel_get_version(struct gtp_tunnel *t) |
| 128 | { |
| 129 | return t->gtp_version; |
| 130 | } |
| 131 | EXPORT_SYMBOL(gtp_tunnel_get_version); |
| 132 | |
| 133 | uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t) |
| 134 | { |
Andreas Schultz | 17c816f | 2016-04-11 16:10:03 +0200 | [diff] [blame] | 135 | return t->u.v0.tid; |
Pablo Neira Ayuso | 1853295 | 2014-02-22 22:09:59 +0100 | [diff] [blame] | 136 | } |
| 137 | EXPORT_SYMBOL(gtp_tunnel_get_tid); |
Pablo Neira Ayuso | b976ffa | 2014-03-20 13:56:55 +0100 | [diff] [blame] | 138 | |
| 139 | uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t) |
| 140 | { |
Andreas Schultz | 17c816f | 2016-04-11 16:10:03 +0200 | [diff] [blame] | 141 | return t->u.v0.flowid; |
Pablo Neira Ayuso | b976ffa | 2014-03-20 13:56:55 +0100 | [diff] [blame] | 142 | } |
| 143 | EXPORT_SYMBOL(gtp_tunnel_get_flowid); |
Andreas Schultz | 17c816f | 2016-04-11 16:10:03 +0200 | [diff] [blame] | 144 | |
| 145 | uint32_t gtp_tunnel_get_i_tei(struct gtp_tunnel *t) |
| 146 | { |
| 147 | return t->u.v1.i_tei; |
| 148 | } |
| 149 | EXPORT_SYMBOL(gtp_tunnel_get_i_tei); |
| 150 | |
| 151 | uint32_t gtp_tunnel_get_o_tei(struct gtp_tunnel *t) |
| 152 | { |
| 153 | return t->u.v1.o_tei; |
| 154 | } |
| 155 | EXPORT_SYMBOL(gtp_tunnel_get_o_tei); |