blob: 6bb0d8529037ad9e3cdc4d01d6b91ef489a19fd6 [file] [log] [blame]
Pau Espin Pedrolf612ffe2019-08-20 13:24:55 +02001/*
2 * misc helpers
3 * Copyright 2019 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
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#include "../gtp/pdp.h"
13
14#include "ippool.h"
15#include "in46_addr.h"
16
17/*! Get the peer of pdp based on IP version used.
18* \param[in] pdp PDP context to select the peer from.
19* \param[in] v4v6 IP version to select. Valid values are 4 and 6.
20* \returns The selected peer matching the given IP version. NULL if not present.
21*/
22struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6) {
23 uint8_t i;
24
25 for (i = 0; i < 2; i++) {
26 struct ippoolm_t * ippool = pdp->peer[i];
27 if (!ippool)
28 continue;
29 if (is_ipv6 && in46a_is_v6(&ippool->addr))
30 return ippool;
31 else if (!is_ipv6 && in46a_is_v4(&ippool->addr))
32 return ippool;
33 }
34 return NULL;
35}