1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164 |
- #ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
- #define ZEPHYR_INCLUDE_NET_NET_PKT_H_
- #include <zephyr/types.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>
- #include <net/ethernet_vlan.h>
- #include <net/ptp_time.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct net_context;
- struct canbus_net_isotp_tx_ctx;
- struct canbus_net_isotp_rx_ctx;
- struct net_pkt_cursor {
-
- struct net_buf *buf;
-
- uint8_t *pos;
- };
- struct net_pkt {
-
- intptr_t fifo;
-
- struct k_mem_slab *slab;
-
- union {
- struct net_buf *frags;
- struct net_buf *buffer;
- };
-
- struct net_pkt_cursor cursor;
-
- struct net_context *context;
-
- struct net_if *iface;
-
- #if defined(CONFIG_NET_ROUTING)
- struct net_if *orig_iface;
- #endif
- #if defined(CONFIG_NET_PKT_TIMESTAMP)
-
- struct net_ptp_time timestamp;
- #endif
- #if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
- struct {
-
- uint32_t create_time;
- #if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
- defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
-
- struct {
- uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
- int count;
- } detail;
- #endif
- };
- #endif
- #if defined(CONFIG_NET_PKT_TXTIME)
-
- uint64_t txtime;
- #endif
-
- atomic_t atomic_ref;
-
- struct net_linkaddr lladdr_src;
- struct net_linkaddr lladdr_dst;
- #if defined(CONFIG_NET_TCP2)
-
- sys_snode_t next;
- #endif
- uint8_t ip_hdr_len;
- uint8_t overwrite : 1;
- uint8_t sent_or_eof: 1;
- union {
- uint8_t pkt_queued: 1;
- uint8_t gptp_pkt: 1;
- };
- uint8_t forwarding : 1;
- uint8_t family : 3;
- union {
- uint8_t ipv4_auto_arp_msg : 1;
- uint8_t lldp_pkt : 1;
- uint8_t ppp_msg : 1;
- };
- #if defined(CONFIG_NET_TCP)
- uint8_t tcp_first_msg : 1;
- #endif
- uint8_t captured : 1;
- uint8_t l2_bridged : 1;
- union {
-
- uint8_t ipv6_hop_limit;
- uint8_t ipv4_ttl;
- };
- union {
- #if defined(CONFIG_NET_IPV4)
- uint8_t ipv4_opts_len;
- #endif
- #if defined(CONFIG_NET_IPV6)
- uint16_t ipv6_ext_len;
- #endif
- };
-
- uint8_t priority;
- #if defined(CONFIG_NET_VLAN)
-
- uint16_t vlan_tci;
- #endif
- #if defined(CONFIG_NET_IPV6)
-
- uint16_t ipv6_prev_hdr_start;
- #if defined(CONFIG_NET_IPV6_FRAGMENT)
- uint16_t ipv6_fragment_flags;
- uint32_t ipv6_fragment_id;
- uint16_t ipv6_frag_hdr_start;
- #endif
- uint8_t ipv6_ext_opt_len;
- uint8_t ipv6_next_hdr;
- #endif
- #if defined(CONFIG_IEEE802154)
- uint8_t ieee802154_rssi;
- uint8_t ieee802154_lqi;
- uint8_t ieee802154_arb : 1;
- uint8_t ieee802154_ack_fpb : 1;
- uint8_t ieee802154_frame_secured : 1;
- uint8_t ieee802154_mac_hdr_rdy : 1;
- #if defined(CONFIG_IEEE802154_2015)
- uint8_t ieee802154_fv2015 : 1;
- uint8_t ieee802154_ack_seb : 1;
- uint32_t ieee802154_ack_fc;
- uint8_t ieee802154_ack_keyid;
- #endif
- #endif
- #if defined(CONFIG_NET_L2_CANBUS)
- union {
- struct canbus_isotp_tx_ctx *canbus_tx_ctx;
- struct canbus_isotp_rx_ctx *canbus_rx_ctx;
- };
- #endif
-
- };
- static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
- {
- return net_if_get_link_addr(pkt->iface);
- }
- static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
- {
- return pkt->context;
- }
- static inline void net_pkt_set_context(struct net_pkt *pkt,
- struct net_context *ctx)
- {
- pkt->context = ctx;
- }
- static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
- {
- return pkt->iface;
- }
- static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
- {
- pkt->iface = iface;
-
- if (iface) {
- pkt->lladdr_src.type = net_if_get_link_addr(iface)->type;
- pkt->lladdr_dst.type = net_if_get_link_addr(iface)->type;
- }
- }
- static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
- {
- #if defined(CONFIG_NET_ROUTING)
- return pkt->orig_iface;
- #else
- return pkt->iface;
- #endif
- }
- static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
- struct net_if *iface)
- {
- #if defined(CONFIG_NET_ROUTING)
- pkt->orig_iface = iface;
- #endif
- }
- static inline uint8_t net_pkt_family(struct net_pkt *pkt)
- {
- return pkt->family;
- }
- static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
- {
- pkt->family = family;
- }
- static inline bool net_pkt_is_gptp(struct net_pkt *pkt)
- {
- return !!(pkt->gptp_pkt);
- }
- static inline void net_pkt_set_gptp(struct net_pkt *pkt, bool is_gptp)
- {
- pkt->gptp_pkt = is_gptp;
- }
- static inline bool net_pkt_is_captured(struct net_pkt *pkt)
- {
- return !!(pkt->captured);
- }
- static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
- {
- pkt->captured = is_captured;
- }
- static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
- {
- return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
- }
- static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
- {
- if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
- pkt->l2_bridged = is_l2_bridged;
- }
- }
- static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
- {
- return pkt->ip_hdr_len;
- }
- static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
- {
- pkt->ip_hdr_len = len;
- }
- static inline uint8_t net_pkt_sent(struct net_pkt *pkt)
- {
- return pkt->sent_or_eof;
- }
- static inline void net_pkt_set_sent(struct net_pkt *pkt, bool sent)
- {
- pkt->sent_or_eof = sent;
- }
- static inline uint8_t net_pkt_queued(struct net_pkt *pkt)
- {
- return pkt->pkt_queued;
- }
- static inline void net_pkt_set_queued(struct net_pkt *pkt, bool send)
- {
- pkt->pkt_queued = send;
- }
- static inline uint8_t net_pkt_tcp_1st_msg(struct net_pkt *pkt)
- {
- #if defined(CONFIG_NET_TCP)
- return pkt->tcp_first_msg;
- #else
- return true;
- #endif
- }
- static inline void net_pkt_set_tcp_1st_msg(struct net_pkt *pkt, bool is_1st)
- {
- #if defined(CONFIG_NET_TCP)
- pkt->tcp_first_msg = is_1st;
- #else
- ARG_UNUSED(pkt);
- ARG_UNUSED(is_1st);
- #endif
- }
- #if defined(CONFIG_NET_SOCKETS)
- static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
- {
- return pkt->sent_or_eof;
- }
- static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
- {
- pkt->sent_or_eof = eof;
- }
- #endif
- #if defined(CONFIG_NET_ROUTE)
- static inline bool net_pkt_forwarding(struct net_pkt *pkt)
- {
- return pkt->forwarding;
- }
- static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
- {
- pkt->forwarding = forward;
- }
- #else
- static inline bool net_pkt_forwarding(struct net_pkt *pkt)
- {
- return false;
- }
- #endif
- #if defined(CONFIG_NET_IPV4)
- static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
- {
- return pkt->ipv4_ttl;
- }
- static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
- uint8_t ttl)
- {
- pkt->ipv4_ttl = ttl;
- }
- static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
- {
- return pkt->ipv4_opts_len;
- }
- static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
- uint8_t opts_len)
- {
- pkt->ipv4_opts_len = opts_len;
- }
- #else
- static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
- uint8_t ttl)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(ttl);
- }
- static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
- uint8_t opts_len)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(opts_len);
- }
- #endif
- #if defined(CONFIG_NET_IPV6)
- static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
- {
- return pkt->ipv6_ext_opt_len;
- }
- static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
- uint8_t len)
- {
- pkt->ipv6_ext_opt_len = len;
- }
- static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
- {
- return pkt->ipv6_next_hdr;
- }
- static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
- uint8_t next_hdr)
- {
- pkt->ipv6_next_hdr = next_hdr;
- }
- static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
- {
- return pkt->ipv6_ext_len;
- }
- static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
- {
- pkt->ipv6_ext_len = len;
- }
- static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
- {
- return pkt->ipv6_prev_hdr_start;
- }
- static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
- uint16_t offset)
- {
- pkt->ipv6_prev_hdr_start = offset;
- }
- static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
- {
- return pkt->ipv6_hop_limit;
- }
- static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
- uint8_t hop_limit)
- {
- pkt->ipv6_hop_limit = hop_limit;
- }
- #else
- static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
- uint8_t len)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(len);
- }
- static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
- uint8_t next_hdr)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(next_hdr);
- }
- static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(len);
- }
- static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
- uint16_t offset)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(offset);
- }
- static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
- uint8_t hop_limit)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(hop_limit);
- }
- #endif
- static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
- {
- #if defined(CONFIG_NET_IPV6)
- return pkt->ipv6_ext_len;
- #elif defined(CONFIG_NET_IPV4)
- return pkt->ipv4_opts_len;
- #else
- ARG_UNUSED(pkt);
- return 0;
- #endif
- }
- #if defined(CONFIG_NET_IPV6_FRAGMENT)
- static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
- {
- return pkt->ipv6_frag_hdr_start;
- }
- static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
- uint16_t start)
- {
- pkt->ipv6_frag_hdr_start = start;
- }
- static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
- {
- return pkt->ipv6_fragment_flags & NET_IPV6_FRAGH_OFFSET_MASK;
- }
- static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
- {
- return (pkt->ipv6_fragment_flags & 0x01) != 0;
- }
- static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
- uint16_t flags)
- {
- pkt->ipv6_fragment_flags = flags;
- }
- static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
- {
- return pkt->ipv6_fragment_id;
- }
- static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
- uint32_t id)
- {
- pkt->ipv6_fragment_id = id;
- }
- #else
- static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
- uint16_t start)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(start);
- }
- static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
- uint16_t flags)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(flags);
- }
- static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
- uint32_t id)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(id);
- }
- #endif
- static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
- {
- return pkt->priority;
- }
- static inline void net_pkt_set_priority(struct net_pkt *pkt,
- uint8_t priority)
- {
- pkt->priority = priority;
- }
- #if defined(CONFIG_NET_VLAN)
- static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
- {
- return net_eth_vlan_get_vid(pkt->vlan_tci);
- }
- static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
- {
- pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
- }
- static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
- {
- return net_eth_vlan_get_pcp(pkt->vlan_tci);
- }
- static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
- uint8_t priority)
- {
- pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
- }
- static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
- {
- return net_eth_vlan_get_dei(pkt->vlan_tci);
- }
- static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
- {
- pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
- }
- static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
- {
- pkt->vlan_tci = tci;
- }
- static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
- {
- return pkt->vlan_tci;
- }
- #else
- static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
- {
- return NET_VLAN_TAG_UNSPEC;
- }
- static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(tag);
- }
- static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
- {
- return false;
- }
- static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(dei);
- }
- static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
- {
- return NET_VLAN_TAG_UNSPEC;
- }
- static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(tci);
- }
- #endif
- #if defined(CONFIG_NET_PKT_TIMESTAMP)
- static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
- {
- return &pkt->timestamp;
- }
- static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
- struct net_ptp_time *timestamp)
- {
- pkt->timestamp.second = timestamp->second;
- pkt->timestamp.nanosecond = timestamp->nanosecond;
- }
- #else
- static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return NULL;
- }
- static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
- struct net_ptp_time *timestamp)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(timestamp);
- }
- #endif
- #if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
- static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
- {
- return pkt->create_time;
- }
- static inline void net_pkt_set_create_time(struct net_pkt *pkt,
- uint32_t create_time)
- {
- pkt->create_time = create_time;
- }
- #else
- static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0U;
- }
- static inline void net_pkt_set_create_time(struct net_pkt *pkt,
- uint32_t create_time)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(create_time);
- }
- #endif
- #if defined(CONFIG_NET_PKT_TXTIME)
- static inline uint64_t net_pkt_txtime(struct net_pkt *pkt)
- {
- return pkt->txtime;
- }
- static inline void net_pkt_set_txtime(struct net_pkt *pkt, uint64_t txtime)
- {
- pkt->txtime = txtime;
- }
- #else
- static inline uint64_t net_pkt_txtime(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_set_txtime(struct net_pkt *pkt, uint64_t txtime)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(txtime);
- }
- #endif
- #if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
- defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
- static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
- {
- return pkt->detail.stat;
- }
- static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
- {
- return pkt->detail.count;
- }
- static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
- {
- memset(&pkt->detail, 0, sizeof(pkt->detail));
- }
- static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
- uint32_t tick)
- {
- if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
- NET_ERR("Detail stats count overflow (%d >= %d)",
- pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
- return;
- }
- pkt->detail.stat[pkt->detail.count++] = tick;
- }
- #define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
- #define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
- #else
- static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return NULL;
- }
- static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return 0;
- }
- static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- }
- static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(tick);
- }
- #define net_pkt_set_tx_stats_tick(pkt, tick)
- #define net_pkt_set_rx_stats_tick(pkt, tick)
- #endif
- static inline size_t net_pkt_get_len(struct net_pkt *pkt)
- {
- return net_buf_frags_len(pkt->frags);
- }
- static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
- {
- return pkt->frags->data;
- }
- static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
- {
- return pkt->frags->data;
- }
- static inline bool net_pkt_is_empty(struct net_pkt *pkt)
- {
- return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
- }
- static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
- {
- return &pkt->lladdr_src;
- }
- static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
- {
- return &pkt->lladdr_dst;
- }
- static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
- {
- uint8_t *addr = net_pkt_lladdr_src(pkt)->addr;
- net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
- net_pkt_lladdr_dst(pkt)->addr = addr;
- }
- static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
- {
- net_pkt_lladdr_src(pkt)->addr = NULL;
- net_pkt_lladdr_src(pkt)->len = 0U;
- }
- #if defined(CONFIG_IEEE802154) || defined(CONFIG_IEEE802154_RAW_MODE)
- static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
- {
- return pkt->ieee802154_rssi;
- }
- static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt,
- uint8_t rssi)
- {
- pkt->ieee802154_rssi = rssi;
- }
- static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt)
- {
- return pkt->ieee802154_lqi;
- }
- static inline void net_pkt_set_ieee802154_lqi(struct net_pkt *pkt,
- uint8_t lqi)
- {
- pkt->ieee802154_lqi = lqi;
- }
- static inline bool net_pkt_ieee802154_arb(struct net_pkt *pkt)
- {
- return pkt->ieee802154_arb;
- }
- static inline void net_pkt_set_ieee802154_arb(struct net_pkt *pkt, bool arb)
- {
- pkt->ieee802154_arb = arb;
- }
- static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt)
- {
- return pkt->ieee802154_ack_fpb;
- }
- static inline void net_pkt_set_ieee802154_ack_fpb(struct net_pkt *pkt,
- bool fpb)
- {
- pkt->ieee802154_ack_fpb = fpb;
- }
- static inline bool net_pkt_ieee802154_frame_secured(struct net_pkt *pkt)
- {
- return pkt->ieee802154_frame_secured;
- }
- static inline void net_pkt_set_ieee802154_frame_secured(struct net_pkt *pkt,
- bool secured)
- {
- pkt->ieee802154_frame_secured = secured;
- }
- static inline bool net_pkt_ieee802154_mac_hdr_rdy(struct net_pkt *pkt)
- {
- return pkt->ieee802154_mac_hdr_rdy;
- }
- static inline void net_pkt_set_ieee802154_mac_hdr_rdy(struct net_pkt *pkt,
- bool rdy)
- {
- pkt->ieee802154_mac_hdr_rdy = rdy;
- }
- #if defined(CONFIG_IEEE802154_2015)
- static inline bool net_pkt_ieee802154_fv2015(struct net_pkt *pkt)
- {
- return pkt->ieee802154_fv2015;
- }
- static inline void net_pkt_set_ieee802154_fv2015(struct net_pkt *pkt, bool fv2015)
- {
- pkt->ieee802154_fv2015 = fv2015;
- }
- static inline bool net_pkt_ieee802154_ack_seb(struct net_pkt *pkt)
- {
- return pkt->ieee802154_ack_seb;
- }
- static inline void net_pkt_set_ieee802154_ack_seb(struct net_pkt *pkt, bool seb)
- {
- pkt->ieee802154_ack_seb = seb;
- }
- static inline uint32_t net_pkt_ieee802154_ack_fc(struct net_pkt *pkt)
- {
- return pkt->ieee802154_ack_fc;
- }
- static inline void net_pkt_set_ieee802154_ack_fc(struct net_pkt *pkt,
- uint32_t fc)
- {
- pkt->ieee802154_ack_fc = fc;
- }
- static inline uint8_t net_pkt_ieee802154_ack_keyid(struct net_pkt *pkt)
- {
- return pkt->ieee802154_ack_keyid;
- }
- static inline void net_pkt_set_ieee802154_ack_keyid(struct net_pkt *pkt,
- uint8_t keyid)
- {
- pkt->ieee802154_ack_keyid = keyid;
- }
- #endif
- #endif
- #if defined(CONFIG_NET_IPV4_AUTO)
- static inline bool net_pkt_ipv4_auto(struct net_pkt *pkt)
- {
- return pkt->ipv4_auto_arp_msg;
- }
- static inline void net_pkt_set_ipv4_auto(struct net_pkt *pkt,
- bool is_auto_arp_msg)
- {
- pkt->ipv4_auto_arp_msg = is_auto_arp_msg;
- }
- #else
- static inline bool net_pkt_ipv4_auto(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return false;
- }
- static inline void net_pkt_set_ipv4_auto(struct net_pkt *pkt,
- bool is_auto_arp_msg)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(is_auto_arp_msg);
- }
- #endif
- #if defined(CONFIG_NET_LLDP)
- static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
- {
- return pkt->lldp_pkt;
- }
- static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
- {
- pkt->lldp_pkt = is_lldp;
- }
- #else
- static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return false;
- }
- static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(is_lldp);
- }
- #endif
- #if defined(CONFIG_NET_PPP)
- static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
- {
- return pkt->ppp_msg;
- }
- static inline void net_pkt_set_ppp(struct net_pkt *pkt,
- bool is_ppp_msg)
- {
- pkt->ppp_msg = is_ppp_msg;
- }
- #else
- static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
- {
- ARG_UNUSED(pkt);
- return false;
- }
- static inline void net_pkt_set_ppp(struct net_pkt *pkt,
- bool is_ppp_msg)
- {
- ARG_UNUSED(pkt);
- ARG_UNUSED(is_ppp_msg);
- }
- #endif
- #define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
- #define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
- static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
- {
- net_if_ipv6_select_src_addr(net_context_get_iface(
- net_pkt_context(pkt)),
- &NET_IPV6_HDR(pkt)->src);
- }
- static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
- {
- pkt->overwrite = overwrite;
- }
- static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
- {
- return pkt->overwrite;
- }
- #define NET_PKT_SLAB_DEFINE(name, count) \
- K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4)
- #define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
- #define NET_PKT_DATA_POOL_DEFINE(name, count) \
- NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
- CONFIG_NET_BUF_USER_DATA_SIZE, NULL)
- #if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
- (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
- #define NET_PKT_DEBUG_ENABLED
- #endif
- #if defined(NET_PKT_DEBUG_ENABLED)
- struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
- k_timeout_t timeout,
- const char *caller,
- int line);
- #define net_pkt_get_reserve_data(pool, timeout) \
- net_pkt_get_reserve_data_debug(pool, timeout, __func__, __LINE__)
- struct net_buf *net_pkt_get_reserve_rx_data_debug(k_timeout_t timeout,
- const char *caller,
- int line);
- #define net_pkt_get_reserve_rx_data(timeout) \
- net_pkt_get_reserve_rx_data_debug(timeout, __func__, __LINE__)
- struct net_buf *net_pkt_get_reserve_tx_data_debug(k_timeout_t timeout,
- const char *caller,
- int line);
- #define net_pkt_get_reserve_tx_data(timeout) \
- net_pkt_get_reserve_tx_data_debug(timeout, __func__, __LINE__)
- struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt,
- k_timeout_t timeout,
- const char *caller, int line);
- #define net_pkt_get_frag(pkt, timeout) \
- net_pkt_get_frag_debug(pkt, timeout, __func__, __LINE__)
- void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
- #define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
- struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
- int line);
- #define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
- struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
- const char *caller, int line);
- #define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
- void net_pkt_frag_unref_debug(struct net_buf *frag,
- const char *caller, int line);
- #define net_pkt_frag_unref(frag) \
- net_pkt_frag_unref_debug(frag, __func__, __LINE__)
- struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
- struct net_buf *parent,
- struct net_buf *frag,
- const char *caller, int line);
- #define net_pkt_frag_del(pkt, parent, frag) \
- net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
- void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
- const char *caller, int line);
- #define net_pkt_frag_add(pkt, frag) \
- net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
- void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
- const char *caller, int line);
- #define net_pkt_frag_insert(pkt, frag) \
- net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
- #endif
- #if defined(NET_PKT_DEBUG_ENABLED)
- void net_pkt_print_frags(struct net_pkt *pkt);
- #else
- #define net_pkt_print_frags(pkt)
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_buf *net_pkt_get_reserve_rx_data(k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_buf *net_pkt_get_reserve_tx_data(k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- void net_pkt_unref(struct net_pkt *pkt);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- void net_pkt_frag_unref(struct net_buf *frag);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_buf *net_pkt_frag_del(struct net_pkt *pkt,
- struct net_buf *parent,
- struct net_buf *frag);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
- #endif
- bool net_pkt_compact(struct net_pkt *pkt);
- void net_pkt_get_info(struct k_mem_slab **rx,
- struct k_mem_slab **tx,
- struct net_buf_pool **rx_data,
- struct net_buf_pool **tx_data);
- #if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
- void net_pkt_print(void);
- typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
- struct net_buf *buf,
- const char *func_alloc,
- int line_alloc,
- const char *func_free,
- int line_free,
- bool in_use,
- void *user_data);
- void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
- const char *net_pkt_slab2str(struct k_mem_slab *slab);
- const char *net_pkt_pool2str(struct net_buf_pool *pool);
- #else
- #define net_pkt_print(...)
- #endif
- #if defined(NET_PKT_DEBUG_ENABLED)
- struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
- const char *caller, int line);
- #define net_pkt_alloc(_timeout) \
- net_pkt_alloc_debug(_timeout, __func__, __LINE__)
- struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
- k_timeout_t timeout,
- const char *caller, int line);
- #define net_pkt_alloc_from_slab(_slab, _timeout) \
- net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
- struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
- const char *caller, int line);
- #define net_pkt_rx_alloc(_timeout) \
- net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
- struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
- k_timeout_t timeout,
- const char *caller,
- int line);
- #define net_pkt_alloc_on_iface(_iface, _timeout) \
- net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
- struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
- k_timeout_t timeout,
- const char *caller,
- int line);
- #define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
- net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
- __func__, __LINE__)
- int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
- size_t size,
- enum net_ip_protocol proto,
- k_timeout_t timeout,
- const char *caller, int line);
- #define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
- net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
- __func__, __LINE__)
- struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
- size_t size,
- sa_family_t family,
- enum net_ip_protocol proto,
- k_timeout_t timeout,
- const char *caller,
- int line);
- #define net_pkt_alloc_with_buffer(_iface, _size, _family, \
- _proto, _timeout) \
- net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
- _proto, _timeout, \
- __func__, __LINE__)
- struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
- size_t size,
- sa_family_t family,
- enum net_ip_protocol proto,
- k_timeout_t timeout,
- const char *caller,
- int line);
- #define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
- _proto, _timeout) \
- net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
- _proto, _timeout, \
- __func__, __LINE__)
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_pkt *net_pkt_alloc(k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
- k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_pkt *net_pkt_rx_alloc(k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_pkt *net_pkt_alloc_on_iface(struct net_if *iface,
- k_timeout_t timeout);
- struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
- k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- int net_pkt_alloc_buffer(struct net_pkt *pkt,
- size_t size,
- enum net_ip_protocol proto,
- k_timeout_t timeout);
- #endif
- #if !defined(NET_PKT_DEBUG_ENABLED)
- struct net_pkt *net_pkt_alloc_with_buffer(struct net_if *iface,
- size_t size,
- sa_family_t family,
- enum net_ip_protocol proto,
- k_timeout_t timeout);
- struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
- size_t size,
- sa_family_t family,
- enum net_ip_protocol proto,
- k_timeout_t timeout);
- #endif
- void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
- size_t net_pkt_available_buffer(struct net_pkt *pkt);
- size_t net_pkt_available_payload_buffer(struct net_pkt *pkt,
- enum net_ip_protocol proto);
- void net_pkt_trim_buffer(struct net_pkt *pkt);
- int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
- void net_pkt_cursor_init(struct net_pkt *pkt);
- static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
- struct net_pkt_cursor *backup)
- {
- backup->buf = pkt->cursor.buf;
- backup->pos = pkt->cursor.pos;
- }
- static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
- struct net_pkt_cursor *backup)
- {
- pkt->cursor.buf = backup->buf;
- pkt->cursor.pos = backup->pos;
- }
- static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
- {
- return pkt->cursor.pos;
- }
- int net_pkt_skip(struct net_pkt *pkt, size_t length);
- int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
- int net_pkt_copy(struct net_pkt *pkt_dst,
- struct net_pkt *pkt_src,
- size_t length);
- struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
- struct net_pkt *net_pkt_shallow_clone(struct net_pkt *pkt,
- k_timeout_t timeout);
- int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
- static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
- {
- return net_pkt_read(pkt, data, 1);
- }
- int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
- int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
- int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
- int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
- static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
- {
- return net_pkt_write(pkt, &data, sizeof(uint8_t));
- }
- static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
- {
- uint16_t data_be16 = htons(data);
- return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
- }
- static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
- {
- uint32_t data_be32 = htonl(data);
- return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
- }
- static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
- {
- uint32_t data_le32 = sys_cpu_to_le32(data);
- return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
- }
- static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
- {
- uint16_t data_le16 = sys_cpu_to_le16(data);
- return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
- }
- size_t net_pkt_remaining_data(struct net_pkt *pkt);
- int net_pkt_update_length(struct net_pkt *pkt, size_t length);
- int net_pkt_pull(struct net_pkt *pkt, size_t length);
- uint16_t net_pkt_get_current_offset(struct net_pkt *pkt);
- bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
- size_t net_pkt_get_contiguous_len(struct net_pkt *pkt);
- struct net_pkt_data_access {
- #if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
- void *data;
- #endif
- const size_t size;
- };
- #if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
- #define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
- struct net_pkt_data_access _name = { \
- .size = sizeof(_type), \
- }
- #define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
- NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
- #else
- #define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
- _type _hdr_##_name; \
- struct net_pkt_data_access _name = { \
- .data = &_hdr_##_name, \
- .size = sizeof(_type), \
- }
- #define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
- struct net_pkt_data_access _name = { \
- .data = NULL, \
- .size = sizeof(_type), \
- }
- #endif
- void *net_pkt_get_data(struct net_pkt *pkt,
- struct net_pkt_data_access *access);
- int net_pkt_set_data(struct net_pkt *pkt,
- struct net_pkt_data_access *access);
- static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
- struct net_pkt_data_access *access)
- {
- return net_pkt_skip(pkt, access->size);
- }
- #ifdef __cplusplus
- }
- #endif
- #endif
|