<commit_before>/** @file
 * @brief Network buffer API
 *
 * Network data is passed between different parts of the stack via
 * net_buf struct.
 */

/*
 * 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.
 */

/* Data buffer API - used for all data to/from net */

#ifndef __NBUF_H
#define __NBUF_H

#include <stdint.h>
#include <stdbool.h>

#include <net/buf.h>

#include <net/net_core.h>
#include <net/net_linkaddr.h>
#include <net/net_ip.h>
#include <net/net_if.h>
#include <net/net_context.h>

#ifdef __cplusplus
extern "C" {
#endif

struct net_context;

/** @cond ignore */
enum net_nbuf_type {
	NET_NBUF_RX = 0,
	NET_NBUF_TX = 1,
	NET_NBUF_DATA = 2,
};
/** @endcond */

struct net_nbuf {
	/** @cond ignore */
	enum net_nbuf_type type;
	uint16_t reserve; /* length of the protocol headers */
	uint8_t ll_reserve; /* link layer header length */
	uint8_t family; /* IPv4 vs IPv6 */
	uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
	uint8_t ext_len; /* length of extension headers */
	uint8_t ext_bitmap;
	uint8_t *next_hdr;

	/* Filled by layer 2 when network packet is received. */
	struct net_linkaddr lladdr_src;
	struct net_linkaddr lladdr_dst;

#if defined(CONFIG_NET_IPV6)
	uint8_t ext_opt_len; /* IPv6 ND option length */
#endif
	/* @endcond */

	/** Network connection context */
	struct net_context *context;

	/** Network context token that user can set. This is passed
	 * to user callback when data has been sent.
	 */
	void *token;

	/** Network interface */
	struct net_if *iface;

	/** @cond ignore */
	uint8_t *appdata;  /* application data */
	uint16_t appdatalen;
	/* @endcond */
};

/** @cond ignore */


/* The interface real ll address */
static inline struct net_linkaddr *net_nbuf_ll_if(struct net_buf *buf)
{
	return net_if_get_link_addr(
		((struct net_nbuf *)net_buf_user_data(buf))->iface);
}

static inline struct net_context *net_nbuf_context(struct net_buf *buf)
{
	return ((struct net_nbuf *)net_buf_user_data(buf))->context;
}

static inline void net_nbuf_set_context(struct net_buf *buf,
					struct net_context *ctx)
{
	((struct net_nbuf *)net_buf_user_data(buf))->context = ctx;
}<commit_msg>net: Re-order fields in net_nbuf struct<commit_after>/** @file
 * @brief Network buffer API
 *
 * Network data is passed between different parts of the stack via
 * net_buf struct.
 */

/*
 * 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.
 */

/* Data buffer API - used for all data to/from net */

#ifndef __NBUF_H
#define __NBUF_H

#include <stdint.h>
#include <stdbool.h>

#include <net/buf.h>

#include <net/net_core.h>
#include <net/net_linkaddr.h>
#include <net/net_ip.h>
#include <net/net_if.h>
#include <net/net_context.h>

#ifdef __cplusplus
extern "C" {
#endif

struct net_context;

/** @cond ignore */
enum net_nbuf_type {
	NET_NBUF_RX = 0,
	NET_NBUF_TX = 1,
	NET_NBUF_DATA = 2,
};
/** @endcond */

struct net_nbuf {
	/** Network connection context */
	struct net_context *context;

	/** Network context token that user can set. This is passed
	 * to user callback when data has been sent.
	 */
	void *token;

	/** Network interface */
	struct net_if *iface;

	/** @cond ignore */
	uint8_t *appdata;	/* application data starts here */
	uint8_t *next_hdr;	/* where is the next header */

	/* Filled by layer 2 when network packet is received. */
	struct net_linkaddr lladdr_src;
	struct net_linkaddr lladdr_dst;

	enum net_nbuf_type type;

	uint16_t appdatalen;
	uint16_t reserve;	/* length of the protocol headers */
	uint8_t ll_reserve;	/* link layer header length */
	uint8_t family;		/* IPv4 vs IPv6 */
	uint8_t ip_hdr_len;	/* pre-filled in order to avoid func call */
	uint8_t ext_len;	/* length of extension headers */
	uint8_t ext_bitmap;

#if defined(CONFIG_NET_IPV6)
	uint8_t ext_opt_len; /* IPv6 ND option length */
#endif
	/* @endcond */
};

/** @cond ignore */


/* The interface real ll address */
static inline struct net_linkaddr *net_nbuf_ll_if(struct net_buf *buf)
{
	return net_if_get_link_addr(
		((struct net_nbuf *)net_buf_user_data(buf))->iface);
}

static inline struct net_context *net_nbuf_context(struct net_buf *buf)
{
	return ((struct net_nbuf *)net_buf_user_data(buf))->context;
}

static inline void net_nbuf_set_context(struct net_buf *buf,
					struct net_context *ctx)
{
	((struct net_nbuf *)net_buf_user_data(buf))->context = ctx;
}
{'fraction_non_alphanumeric': 0.10803324099722991, 'fraction_numerical': 0.010341643582640813, 'mean_word_length': 3.95970695970696, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5684269', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1822, 'n_words': 611}