zephyr/subsys/net/ip/ipv4.h
Andy Ross a5b694fbbc net: tcp: Select correct source address for SYNACK packets
The source address for a TCP SYNACK must (obviously) be the same as
the destination address of the SYN that produced it.  But the existing
IP packet creation routines would simply fill in a default address
from the net_context struct, which is correct for *established*
connections, but for the listening socket is generally INADDR_ANY
(i.e. all zeroes) and will result in an arbitrary choice for source
address (e.g. a link-local address on the same interface) which can
easily be wrong.

So we need to pass the correct address all the way down from the SYN
packet handler code through the net_ipv*_create() packet creation
functions.  This requires lots of API plumbing, but relatively little
logic change.

Change-Id: Ic368f8cef6689f8a27cbafd5933a4964d5cc457e
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 08:21:15 -05:00

98 lines
2.9 KiB
C

/** @file
@brief IPv4 related functions
This is not to be included by the application.
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __IPV4_H
#define __IPV4_H
#include <stdint.h>
#include <net/net_ip.h>
#include <net/nbuf.h>
#include <net/net_if.h>
#include <net/net_context.h>
#include "ipv4.h"
/**
* @brief Create IPv4 packet in provided net_buf.
*
* @param buf Network buffer
* @param reserve Link layer reserve
* @param src Source IPv4 address
* @param dst Destination IPv4 address
* @param iface Network interface
* @param next_header Protocol type of the next header after IPv4 header.
*
* @return Return network buffer that contains the IPv4 packet.
*/
struct net_buf *net_ipv4_create_raw(struct net_buf *buf,
uint16_t reserve,
const struct in_addr *src,
const struct in_addr *dst,
struct net_if *iface,
uint8_t next_header);
/**
* @brief Create IPv4 packet in provided net_buf.
*
* @param context Network context for a connection
* @param buf Network buffer
* @param src_addr Source address, or NULL to choose a default
* @param dst_addr Destination IPv4 address
*
* @return Return network buffer that contains the IPv6 packet.
*/
struct net_buf *net_ipv4_create(struct net_context *context,
struct net_buf *buf,
const struct in_addr *src_addr,
const struct in_addr *dst_addr);
/**
* @brief Finalize IPv4 packet. It should be called right before
* sending the packet and after all the data has been added into
* the packet. This function will set the length of the
* packet and calculate the higher protocol checksum if needed.
*
* @param buf Network buffer
* @param next_header Protocol type of the next header after IPv4 header.
*
* @return Return network buffer that contains the IPv4 packet.
*/
struct net_buf *net_ipv4_finalize_raw(struct net_buf *buf,
uint8_t next_header);
/**
* @brief Finalize IPv4 packet. It should be called right before
* sending the packet and after all the data has been added into
* the packet. This function will set the length of the
* packet and calculate the higher protocol checksum if needed.
*
* @param context Network context for a connection
* @param buf Network buffer
*
* @return Return network buffer that contains the IPv4 packet.
*/
struct net_buf *net_ipv4_finalize(struct net_context *context,
struct net_buf *buf);
#endif /* __IPV4_H */