David Howells | be6e670 | 2016-04-04 14:00:32 +0100 | [diff] [blame^] | 1 | /* Utility routines |
| 2 | * |
| 3 | * Copyright (C) 2015 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public Licence |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the Licence, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/ip.h> |
| 13 | #include <linux/udp.h> |
| 14 | #include "ar-internal.h" |
| 15 | |
| 16 | /* |
| 17 | * Set up an RxRPC address from a socket buffer. |
| 18 | */ |
| 19 | void rxrpc_get_addr_from_skb(struct rxrpc_local *local, |
| 20 | const struct sk_buff *skb, |
| 21 | struct sockaddr_rxrpc *srx) |
| 22 | { |
| 23 | memset(srx, 0, sizeof(*srx)); |
| 24 | srx->transport_type = local->srx.transport_type; |
| 25 | srx->transport.family = local->srx.transport.family; |
| 26 | |
| 27 | /* Can we see an ipv4 UDP packet on an ipv6 UDP socket? and vice |
| 28 | * versa? |
| 29 | */ |
| 30 | switch (srx->transport.family) { |
| 31 | case AF_INET: |
| 32 | srx->transport.sin.sin_port = udp_hdr(skb)->source; |
| 33 | srx->transport_len = sizeof(struct sockaddr_in); |
| 34 | memcpy(&srx->transport.sin.sin_addr, &ip_hdr(skb)->saddr, |
| 35 | sizeof(struct in_addr)); |
| 36 | break; |
| 37 | |
| 38 | default: |
| 39 | BUG(); |
| 40 | } |
| 41 | } |