Linux 4.8-rc8
[linux/fpc-iii.git] / net / rxrpc / utils.c
blobb88914d53ca5e10eb63f2172e01609baf1598f4c
1 /* Utility routines
3 * Copyright (C) 2015 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/ip.h>
13 #include <linux/ipv6.h>
14 #include <linux/udp.h>
15 #include "ar-internal.h"
18 * Fill out a peer address from a socket buffer containing a packet.
20 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *srx, struct sk_buff *skb)
22 memset(srx, 0, sizeof(*srx));
24 switch (ntohs(skb->protocol)) {
25 case ETH_P_IP:
26 srx->transport_type = SOCK_DGRAM;
27 srx->transport_len = sizeof(srx->transport.sin);
28 srx->transport.sin.sin_family = AF_INET;
29 srx->transport.sin.sin_port = udp_hdr(skb)->source;
30 srx->transport.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
31 return 0;
33 case ETH_P_IPV6:
34 srx->transport_type = SOCK_DGRAM;
35 srx->transport_len = sizeof(srx->transport.sin6);
36 srx->transport.sin6.sin6_family = AF_INET6;
37 srx->transport.sin6.sin6_port = udp_hdr(skb)->source;
38 srx->transport.sin6.sin6_addr = ipv6_hdr(skb)->saddr;
39 return 0;
41 default:
42 pr_warn_ratelimited("AF_RXRPC: Unknown eth protocol %u\n",
43 ntohs(skb->protocol));
44 return -EAFNOSUPPORT;