Pau Espin Pedrol | 724ecc6 | 2022-11-02 14:57:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * OsmoGGSN - Gateway GPRS Support Node |
| 3 | * Copyright (C) 2002, 2003, 2004 Mondru AB. |
| 4 | * |
| 5 | * The contents of this file may be used under the terms of the GNU |
| 6 | * General Public License Version 2, provided that the above copyright |
| 7 | * notice and this permission notice is included in all copies or |
| 8 | * substantial portions of the software. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #ifndef _GSN_H |
| 13 | #define _GSN_H |
| 14 | |
| 15 | #include <osmocom/core/utils.h> |
| 16 | #include <osmocom/core/defs.h> |
| 17 | #include <osmocom/core/timer.h> |
Pau Espin Pedrol | 9f1f747 | 2022-11-02 19:52:19 +0100 | [diff] [blame] | 18 | #include <osmocom/core/tdef.h> |
Pau Espin Pedrol | b9036af | 2022-11-02 18:17:56 +0100 | [diff] [blame] | 19 | #include <osmocom/core/rate_ctr.h> |
Pau Espin Pedrol | 724ecc6 | 2022-11-02 14:57:24 +0100 | [diff] [blame] | 20 | |
| 21 | #include "pdp.h" |
| 22 | |
| 23 | #define GTP_MODE_GGSN 1 |
| 24 | #define GTP_MODE_SGSN 2 |
| 25 | |
| 26 | #define RESTART_FILE "gsn_restart" |
| 27 | |
Pau Espin Pedrol | 9f1f747 | 2022-11-02 19:52:19 +0100 | [diff] [blame] | 28 | extern struct osmo_tdef gtp_T_defs[]; |
| 29 | |
Pau Espin Pedrol | 724ecc6 | 2022-11-02 14:57:24 +0100 | [diff] [blame] | 30 | /* *********************************************************** |
| 31 | * Information storage for each gsn instance |
| 32 | * |
| 33 | * Normally each instance of the application corresponds to |
| 34 | * one instance of a gsn. |
| 35 | * |
| 36 | * In order to avoid global variables in the application, and |
| 37 | * also in order to allow several instances of a gsn in the same |
| 38 | * application this struct is provided in order to store all |
| 39 | * relevant information related to the gsn. |
| 40 | * |
| 41 | * Note that this does not include information storage for ' |
| 42 | * each pdp context. This is stored in another struct. |
| 43 | *************************************************************/ |
| 44 | |
Pau Espin Pedrol | b9036af | 2022-11-02 18:17:56 +0100 | [diff] [blame] | 45 | enum gsn_rate_ctr_keys { |
| 46 | GSN_CTR_ERR_SOCKET, |
| 47 | GSN_CTR_ERR_READFROM, /* Number of readfrom errors */ |
| 48 | GSN_CTR_ERR_SENDTO, /* Number of sendto errors */ |
| 49 | GSN_CTR_ERR_QUEUEFULL, /* Number of times queue was full */ |
| 50 | GSN_CTR_ERR_SEQ, /* Number of seq out of range */ |
| 51 | GSN_CTR_ERR_ADDRESS, /* GSN address conversion failed */ |
| 52 | GSN_CTR_ERR_UNKNOWN_PDP, /* GSN address conversion failed */ |
| 53 | GSN_CTR_ERR_UNEXPECTED_CAUSE, /* Unexpected cause value received */ |
| 54 | GSN_CTR_ERR_OUT_OF_PDP, /* Out of storage for PDP contexts */ |
| 55 | GSN_CTR_PKT_EMPTY, /* Number of empty packets */ |
| 56 | GSN_CTR_PKT_UNSUP, /* Number of unsupported version 29.60 11.1.1 */ |
| 57 | GSN_CTR_PKT_TOOSHORT, /* Number of too short headers 29.60 11.1.2 */ |
| 58 | GSN_CTR_PKT_UNKNOWN, /* Number of unknown messages 29.60 11.1.3 */ |
| 59 | GSN_CTR_PKT_UNEXPECT, /* Number of unexpected messages 29.60 11.1.4 */ |
| 60 | GSN_CTR_PKT_DUPLICATE, /* Number of duplicate or unsolicited replies */ |
| 61 | GSN_CTR_PKT_MISSING, /* Number of missing information field messages */ |
| 62 | GSN_CTR_PKT_INCORRECT, /* Number of incorrect information field messages */ |
| 63 | GSN_CTR_PKT_INVALID, /* Number of invalid message format messages */ |
| 64 | }; |
| 65 | |
Pau Espin Pedrol | 9f1f747 | 2022-11-02 19:52:19 +0100 | [diff] [blame] | 66 | /* 3GPP TS 29.006 14.1, 14,2 */ |
| 67 | enum gtp_gsn_timers { |
| 68 | GTP_GSN_TIMER_T3_RESPONSE = 3, |
| 69 | GTP_GSN_TIMER_N3_REQUESTS = 1003, |
Pau Espin Pedrol | 3a55b89 | 2022-11-04 11:21:23 +0100 | [diff] [blame] | 70 | GTP_GSN_TIMER_T3_HOLD_RESPONSE = -3, |
Pau Espin Pedrol | 9f1f747 | 2022-11-02 19:52:19 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Pau Espin Pedrol | 724ecc6 | 2022-11-02 14:57:24 +0100 | [diff] [blame] | 73 | struct gsn_t { |
| 74 | /* Parameters related to the network interface */ |
| 75 | |
| 76 | int fd0; /* GTP0 file descriptor */ |
| 77 | int fd1c; /* GTP1 control plane file descriptor */ |
| 78 | int fd1u; /* GTP0 user plane file descriptor */ |
| 79 | int mode; /* Mode of operation: GGSN or SGSN */ |
Oliver Smith | 9bd2711 | 2024-02-22 16:02:37 +0100 | [diff] [blame^] | 80 | struct in_addr gsnc; /* IP address of this gsn for signalling */ |
| 81 | struct in_addr gsnu; /* IP address of this gsn for user traffic */ |
Pau Espin Pedrol | 724ecc6 | 2022-11-02 14:57:24 +0100 | [diff] [blame] | 82 | |
| 83 | /* Parameters related to signalling messages */ |
| 84 | uint16_t seq_next; /* Next sequence number to use */ |
| 85 | int seq_first; /* First packet in queue (oldest timeout) */ |
| 86 | int seq_last; /* Last packet in queue (youngest timeout) */ |
| 87 | |
| 88 | unsigned char restart_counter; /* Increment on restart. Stored on disk */ |
| 89 | char *statedir; /* Disk location for permanent storage */ |
| 90 | void *priv; /* used by libgtp users to attach their own state) */ |
| 91 | struct queue_t *queue_req; /* Request queue */ |
| 92 | struct queue_t *queue_resp; /* Response queue */ |
| 93 | |
| 94 | struct pdp_t pdpa[PDP_MAX]; /* PDP storage */ |
| 95 | struct pdp_t *hashtid[PDP_MAX]; /* Hash table for IMSI + NSAPI */ |
| 96 | |
| 97 | struct osmo_timer_list queue_timer; /* internal queue_{req,resp} timer */ |
| 98 | |
| 99 | /* Call back functions */ |
| 100 | int (*cb_delete_context) (struct pdp_t *); |
| 101 | int (*cb_create_context_ind) (struct pdp_t *); |
| 102 | int (*cb_unsup_ind) (struct sockaddr_in * peer); |
| 103 | int (*cb_extheader_ind) (struct sockaddr_in * peer); |
| 104 | int (*cb_ran_info_relay_ind) (struct sockaddr_in *peer, union gtpie_member **ie); |
| 105 | int (*cb_conf) (int type, int cause, struct pdp_t * pdp, void *cbp); |
| 106 | int (*cb_data_ind) (struct pdp_t * pdp, void *pack, unsigned len); |
| 107 | int (*cb_recovery) (struct sockaddr_in * peer, uint8_t recovery); |
| 108 | int (*cb_recovery2) (struct sockaddr_in * peer, struct pdp_t * pdp, uint8_t recovery); |
| 109 | int (*cb_recovery3) (struct gsn_t *gsn, struct sockaddr_in *peer, struct pdp_t *pdp, uint8_t recovery); |
| 110 | |
| 111 | /* Counters */ |
Pau Espin Pedrol | b9036af | 2022-11-02 18:17:56 +0100 | [diff] [blame] | 112 | struct rate_ctr_group *ctrg; |
Pau Espin Pedrol | 9f1f747 | 2022-11-02 19:52:19 +0100 | [diff] [blame] | 113 | |
| 114 | /* Timers: */ |
| 115 | struct osmo_tdef *tdef; |
Pau Espin Pedrol | 724ecc6 | 2022-11-02 14:57:24 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | /* External API functions */ |
| 119 | |
Oliver Smith | 9bd2711 | 2024-02-22 16:02:37 +0100 | [diff] [blame^] | 120 | extern int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen, |
| 121 | int mode); |
Pau Espin Pedrol | 724ecc6 | 2022-11-02 14:57:24 +0100 | [diff] [blame] | 122 | |
| 123 | extern int gtp_free(struct gsn_t *gsn); |
| 124 | |
| 125 | extern int gtp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp, |
| 126 | uint64_t imsi, uint8_t nsapi) OSMO_DEPRECATED("Use gtp_pdp_newpdp() instead"); |
| 127 | extern int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp); |
| 128 | extern int gtp_freepdp_teardown(struct gsn_t *gsn, struct pdp_t *pdp); |
| 129 | |
| 130 | extern int gtp_create_context_req(struct gsn_t *gsn, struct pdp_t *pdp, |
| 131 | void *cbp); |
| 132 | |
| 133 | extern int gtp_set_cb_create_context_ind(struct gsn_t *gsn, |
| 134 | int (*cb_create_context_ind) (struct |
| 135 | pdp_t * |
| 136 | pdp)); |
| 137 | extern int gtp_set_cb_data_ind(struct gsn_t *gsn, |
| 138 | int (*cb_data_ind) (struct pdp_t * pdp, |
| 139 | void *pack, unsigned len)); |
| 140 | extern int gtp_set_cb_delete_context(struct gsn_t *gsn, |
| 141 | int (*cb_delete_context) (struct pdp_t * |
| 142 | pdp)); |
| 143 | /*extern int gtp_set_cb_create_context(struct gsn_t *gsn, |
| 144 | int (*cb_create_context) (struct pdp_t* pdp)); */ |
| 145 | |
| 146 | extern int gtp_set_cb_unsup_ind(struct gsn_t *gsn, |
| 147 | int (*cb) (struct sockaddr_in * peer)); |
| 148 | |
| 149 | extern int gtp_set_cb_extheader_ind(struct gsn_t *gsn, |
| 150 | int (*cb) (struct sockaddr_in * peer)); |
| 151 | |
| 152 | extern int gtp_set_cb_ran_info_relay_ind(struct gsn_t *gsn, |
| 153 | int (*cb) (struct sockaddr_in * peer, union gtpie_member **ie)); |
| 154 | |
| 155 | extern int gtp_set_cb_conf(struct gsn_t *gsn, |
| 156 | int (*cb) (int type, int cause, struct pdp_t * pdp, |
| 157 | void *cbp)); |
| 158 | |
| 159 | int gtp_set_cb_recovery(struct gsn_t *gsn, |
| 160 | int (*cb) (struct sockaddr_in * peer, |
| 161 | uint8_t recovery)) |
| 162 | OSMO_DEPRECATED("Use gtp_set_cb_recovery2() instead, to obtain pdp ctx originating the recovery"); |
| 163 | int gtp_set_cb_recovery2(struct gsn_t *gsn, |
| 164 | int (*cb) (struct sockaddr_in * peer, |
| 165 | struct pdp_t * pdp, |
| 166 | uint8_t recovery)) |
| 167 | OSMO_DEPRECATED("Use gtp_set_cb_recovery3() instead, to obtain gsn handling the recovery"); |
| 168 | int gtp_set_cb_recovery3(struct gsn_t *gsn, |
| 169 | int (*cb) (struct gsn_t * gsn, struct sockaddr_in * peer, |
| 170 | struct pdp_t * pdp, |
| 171 | uint8_t recovery)); |
| 172 | void gtp_clear_queues(struct gsn_t *gsn); |
| 173 | extern int gtp_fd(struct gsn_t *gsn); |
| 174 | |
| 175 | extern int gtp_retrans(struct gsn_t *gsn) OSMO_DEPRECATED("This API is a no-op, libgtp already does the job internally"); |
| 176 | extern int gtp_retranstimeout(struct gsn_t *gsn, struct timeval *timeout) OSMO_DEPRECATED("This API is a no-op and will return a 1 day timeout"); |
| 177 | |
| 178 | /* Internal APIs: */ |
| 179 | void gtp_queue_timer_start(struct gsn_t *gsn); |
| 180 | |
| 181 | #endif /* !_GSN_H */ |