File: bind.c

package info (click to toggle)
linux 6.16.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,724,576 kB
  • sloc: ansic: 26,558,545; asm: 271,315; sh: 143,998; python: 72,469; makefile: 57,126; perl: 36,821; xml: 19,553; cpp: 5,820; yacc: 4,915; lex: 2,955; awk: 1,667; sed: 28; ruby: 25
file content (55 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: GPL-2.0
/*  OpenVPN data channel offload
 *
 *  Copyright (C) 2012-2025 OpenVPN, Inc.
 *
 *  Author:	James Yonan <james@openvpn.net>
 *		Antonio Quartulli <antonio@openvpn.net>
 */

#include <linux/netdevice.h>
#include <linux/socket.h>

#include "ovpnpriv.h"
#include "bind.h"
#include "peer.h"

/**
 * ovpn_bind_from_sockaddr - retrieve binding matching sockaddr
 * @ss: the sockaddr to match
 *
 * Return: the bind matching the passed sockaddr if found, NULL otherwise
 */
struct ovpn_bind *ovpn_bind_from_sockaddr(const struct sockaddr_storage *ss)
{
	struct ovpn_bind *bind;
	size_t sa_len;

	if (ss->ss_family == AF_INET)
		sa_len = sizeof(struct sockaddr_in);
	else if (ss->ss_family == AF_INET6)
		sa_len = sizeof(struct sockaddr_in6);
	else
		return ERR_PTR(-EAFNOSUPPORT);

	bind = kzalloc(sizeof(*bind), GFP_ATOMIC);
	if (unlikely(!bind))
		return ERR_PTR(-ENOMEM);

	memcpy(&bind->remote, ss, sa_len);

	return bind;
}

/**
 * ovpn_bind_reset - assign new binding to peer
 * @peer: the peer whose binding has to be replaced
 * @new: the new bind to assign
 */
void ovpn_bind_reset(struct ovpn_peer *peer, struct ovpn_bind *new)
{
	lockdep_assert_held(&peer->lock);

	kfree_rcu(rcu_replace_pointer(peer->bind, new,
				      lockdep_is_held(&peer->lock)), rcu);
}