From patchwork Sun Jun 24 22:40:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duncan Hare X-Patchwork-Id: 934006 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=synoia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=yahoo.com header.i=@yahoo.com header.b="qASSX4Fx"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41DS2c1HDvz9ry1 for ; Mon, 25 Jun 2018 08:41:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B913EC21DD7; Sun, 24 Jun 2018 22:41:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CD6E2C21C2C; Sun, 24 Jun 2018 22:40:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 75346C21C2C; Sun, 24 Jun 2018 22:40:58 +0000 (UTC) Received: from sonic304-29.consmr.mail.gq1.yahoo.com (sonic304-29.consmr.mail.gq1.yahoo.com [98.137.68.210]) by lists.denx.de (Postfix) with ESMTPS id BDD74C21C27 for ; Sun, 24 Jun 2018 22:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1529880055; bh=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D2b5YMli70oagVGBw bU51f7gTUUV6zjNL4cFaqI2NRRcNTrTrjXRYdMSG_fyjVrkmm6SKzMxZWBqxWKd26MHOQrzteeAD T2plbhb453pLpmxN9tcGLpXxTOt_JjbKSJYt2JjtCfbKCqpC0hAL6d8PZflm2KLLbQgy4akJsK1b WtpI64TzbMpXEWlNvLb0848KFIAxdJ5mwcZF1dGGI0NW19e8dIH1vhj8O_8Nd8apFa3Aq8qs3Sit _cX96SMVGJN250c54C1oUPDvKAyjGHlquixsyyddRh3jbCDKO1OJyRxIHt7t0DCW7X1M9162iFNg uR0OrhFn6xarH60xDqkXBNGAs_TuOpbYZVuVLuTg- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.gq1.yahoo.com with HTTP; Sun, 24 Jun 2018 22:40:55 +0000 Received: from 68-95-124-113.lightspeed.irvnca.sbcglobal.net (EHLO raspberrypi.Danum.local) ([68.95.124.113]) by smtp402.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID f29df259cf5e3dfe6ff6ef53a971ed9f; Sun, 24 Jun 2018 22:40:54 +0000 (UTC) From: DH@synoia.com To: DuncanCHare@yahoo.com Date: Sun, 24 Jun 2018 15:40:41 -0700 Message-Id: <20180624224043.31503-1-DH@synoia.com> X-Mailer: git-send-email 2.11.0 Cc: Duncan Hare , Joe Hershberger , u-boot@lists.denx.de, Jason Kridner , Jocelyn Bohr Subject: [U-Boot] [PATCH v12 1/3] Consolidating UDP header functions. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Duncan Hare To make it possible to add TCP versions of the same, while reusing IP portions. This patch should not change any behavior. All references to TCP removed Used most recent version of u-boot June 22 13, 2918 Series to fix patman errors over Licensing declaration END Series-notes TCP with Selective Acknowledgment (SACK) is currently the protocol with highest speed transfers, for fast multi-hop networks. END Signed-off-by: Duncan Hare Signed-off-by: Duncan Hare --- include/net.h | 6 +++++- net/net.c | 34 ++++++++++++++++++++++++---------- net/ping.c | 7 +------ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/include/net.h b/include/net.h index 5760685556..a54160fff6 100644 --- a/include/net.h +++ b/include/net.h @@ -593,7 +593,8 @@ int net_set_ether(uchar *xet, const uchar *dest_ethaddr, uint prot); int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot); /* Set IP header */ -void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source); +void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source, + u16 pkt_len, u8 proto); void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, int sport, int len); @@ -667,6 +668,9 @@ static inline void net_send_packet(uchar *pkt, int len) * @param sport Source UDP port * @param payload_len Length of data after the UDP header */ +int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport, + int payload_len, int proto, u8 action, u32 tcp_seq_num, + u32 tcp_ack_num); int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport, int payload_len); diff --git a/net/net.c b/net/net.c index b4563a4cab..f831c34599 100644 --- a/net/net.c +++ b/net/net.c @@ -786,6 +786,14 @@ void net_set_timeout_handler(ulong iv, thand_f *f) int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport, int payload_len) { +return net_send_ip_packet(ether, dest, dport, sport, payload_len, + IPPROTO_UDP, 0, 0, 0); +} + +int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport, + int payload_len, int proto, u8 action, u32 tcp_seq_num, + u32 tcp_ack_num) +{ uchar *pkt; int eth_hdr_size; int pkt_hdr_size; @@ -806,9 +814,15 @@ int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport, pkt = (uchar *)net_tx_packet; eth_hdr_size = net_set_ether(pkt, ether, PROT_IP); - pkt += eth_hdr_size; - net_set_udp_header(pkt, dest, dport, sport, payload_len); - pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE; + + switch (proto) { + case IPPROTO_UDP: + net_set_udp_header(pkt + eth_hdr_size, dest, + dport, sport, payload_len); + pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE; + break; + default: return -EINVAL; + } /* if MAC address was not discovered yet, do an ARP request */ if (memcmp(ether, net_null_ethaddr, 6) == 0) { @@ -1434,7 +1448,8 @@ int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot) } } -void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source) +void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source, + u16 pkt_len, u8 proto) { struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt; @@ -1444,11 +1459,12 @@ void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source) /* IP_HDR_SIZE / 4 (not including UDP) */ ip->ip_hl_v = 0x45; ip->ip_tos = 0; - ip->ip_len = htons(IP_HDR_SIZE); + ip->ip_len = htons(pkt_len); + ip->ip_p = proto; ip->ip_id = htons(net_ip_id++); ip->ip_off = htons(IP_FLAGS_DFRAG); /* Don't fragment */ ip->ip_ttl = 255; - ip->ip_sum = 0; + ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE); /* already in network byte order */ net_copy_ip((void *)&ip->ip_src, &source); /* already in network byte order */ @@ -1468,10 +1484,8 @@ void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, int sport, if (len & 1) pkt[IP_UDP_HDR_SIZE + len] = 0; - net_set_ip_header(pkt, dest, net_ip); - ip->ip_len = htons(IP_UDP_HDR_SIZE + len); - ip->ip_p = IPPROTO_UDP; - ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE); + net_set_ip_header(pkt, dest, net_ip, IP_UDP_HDR_SIZE + len, + IPPROTO_UDP); ip->udp_src = htons(sport); ip->udp_dst = htons(dport); diff --git a/net/ping.c b/net/ping.c index 3e5461a36a..d5d914bf2a 100644 --- a/net/ping.c +++ b/net/ping.c @@ -22,14 +22,9 @@ static void set_icmp_header(uchar *pkt, struct in_addr dest) /* * Construct an IP and ICMP header. */ - struct ip_hdr *ip = (struct ip_hdr *)pkt; struct icmp_hdr *icmp = (struct icmp_hdr *)(pkt + IP_HDR_SIZE); - net_set_ip_header(pkt, dest, net_ip); - - ip->ip_len = htons(IP_ICMP_HDR_SIZE); - ip->ip_p = IPPROTO_ICMP; - ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE); + net_set_ip_header(pkt, dest, net_ip, IP_ICMP_HDR_SIZE, IPPROTO_ICMP); icmp->type = ICMP_ECHO_REQUEST; icmp->code = 0;