mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-27 06:04:23 +08:00
b4d0d230cc
Based on 1 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public licence as published by the free software foundation either version 2 of the licence or at your option any later version extracted by the scancode license scanner the SPDX license identifier GPL-2.0-or-later has been chosen to replace the boilerplate/reference in 114 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190520170857.552531963@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/* Utility routines
|
|
*
|
|
* Copyright (C) 2015 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*/
|
|
|
|
#include <linux/ip.h>
|
|
#include <linux/ipv6.h>
|
|
#include <linux/udp.h>
|
|
#include "ar-internal.h"
|
|
|
|
/*
|
|
* Fill out a peer address from a socket buffer containing a packet.
|
|
*/
|
|
int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *srx, struct sk_buff *skb)
|
|
{
|
|
memset(srx, 0, sizeof(*srx));
|
|
|
|
switch (ntohs(skb->protocol)) {
|
|
case ETH_P_IP:
|
|
srx->transport_type = SOCK_DGRAM;
|
|
srx->transport_len = sizeof(srx->transport.sin);
|
|
srx->transport.sin.sin_family = AF_INET;
|
|
srx->transport.sin.sin_port = udp_hdr(skb)->source;
|
|
srx->transport.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
|
|
return 0;
|
|
|
|
#ifdef CONFIG_AF_RXRPC_IPV6
|
|
case ETH_P_IPV6:
|
|
srx->transport_type = SOCK_DGRAM;
|
|
srx->transport_len = sizeof(srx->transport.sin6);
|
|
srx->transport.sin6.sin6_family = AF_INET6;
|
|
srx->transport.sin6.sin6_port = udp_hdr(skb)->source;
|
|
srx->transport.sin6.sin6_addr = ipv6_hdr(skb)->saddr;
|
|
return 0;
|
|
#endif
|
|
|
|
default:
|
|
pr_warn_ratelimited("AF_RXRPC: Unknown eth protocol %u\n",
|
|
ntohs(skb->protocol));
|
|
return -EAFNOSUPPORT;
|
|
}
|
|
}
|