Merge tag 'iommu-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[linux/fpc-iii.git] / net / rxrpc / utils.c
blob2e4b9d86e8992644881d9a4ccee233b334baadb1
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Utility routines
4 * Copyright (C) 2015 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
8 #include <linux/ip.h>
9 #include <linux/ipv6.h>
10 #include <linux/udp.h>
11 #include "ar-internal.h"
14 * Fill out a peer address from a socket buffer containing a packet.
16 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *srx, struct sk_buff *skb)
18 memset(srx, 0, sizeof(*srx));
20 switch (ntohs(skb->protocol)) {
21 case ETH_P_IP:
22 srx->transport_type = SOCK_DGRAM;
23 srx->transport_len = sizeof(srx->transport.sin);
24 srx->transport.sin.sin_family = AF_INET;
25 srx->transport.sin.sin_port = udp_hdr(skb)->source;
26 srx->transport.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
27 return 0;
29 #ifdef CONFIG_AF_RXRPC_IPV6
30 case ETH_P_IPV6:
31 srx->transport_type = SOCK_DGRAM;
32 srx->transport_len = sizeof(srx->transport.sin6);
33 srx->transport.sin6.sin6_family = AF_INET6;
34 srx->transport.sin6.sin6_port = udp_hdr(skb)->source;
35 srx->transport.sin6.sin6_addr = ipv6_hdr(skb)->saddr;
36 return 0;
37 #endif
39 default:
40 pr_warn_ratelimited("AF_RXRPC: Unknown eth protocol %u\n",
41 ntohs(skb->protocol));
42 return -EAFNOSUPPORT;