Thomas Gleixner | b4d0d23 | 2019-05-20 19:08:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | be6e670 | 2016-04-04 14:00:32 +0100 | [diff] [blame] | 2 | /* Utility routines |
| 3 | * |
| 4 | * Copyright (C) 2015 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | be6e670 | 2016-04-04 14:00:32 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/ip.h> |
David Howells | d991b4a | 2016-06-29 14:40:39 +0100 | [diff] [blame] | 9 | #include <linux/ipv6.h> |
David Howells | be6e670 | 2016-04-04 14:00:32 +0100 | [diff] [blame] | 10 | #include <linux/udp.h> |
| 11 | #include "ar-internal.h" |
| 12 | |
| 13 | /* |
David Howells | d991b4a | 2016-06-29 14:40:39 +0100 | [diff] [blame] | 14 | * Fill out a peer address from a socket buffer containing a packet. |
| 15 | */ |
David Howells | 5a790b7 | 2018-10-04 09:32:28 +0100 | [diff] [blame] | 16 | int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *srx, struct sk_buff *skb) |
David Howells | d991b4a | 2016-06-29 14:40:39 +0100 | [diff] [blame] | 17 | { |
| 18 | memset(srx, 0, sizeof(*srx)); |
| 19 | |
| 20 | switch (ntohs(skb->protocol)) { |
| 21 | case ETH_P_IP: |
David Howells | 46894a1 | 2018-10-04 09:32:28 +0100 | [diff] [blame] | 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; |
David Howells | d991b4a | 2016-06-29 14:40:39 +0100 | [diff] [blame] | 27 | return 0; |
| 28 | |
David Howells | d191274 | 2016-09-17 07:26:01 +0100 | [diff] [blame] | 29 | #ifdef CONFIG_AF_RXRPC_IPV6 |
David Howells | d991b4a | 2016-06-29 14:40:39 +0100 | [diff] [blame] | 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; |
David Howells | d191274 | 2016-09-17 07:26:01 +0100 | [diff] [blame] | 37 | #endif |
David Howells | d991b4a | 2016-06-29 14:40:39 +0100 | [diff] [blame] | 38 | |
| 39 | default: |
| 40 | pr_warn_ratelimited("AF_RXRPC: Unknown eth protocol %u\n", |
| 41 | ntohs(skb->protocol)); |
| 42 | return -EAFNOSUPPORT; |
| 43 | } |
| 44 | } |