7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
9 #include <linux/string.h>
12 #include <linux/export.h>
17 #define PKT_LEN_WHEN_EXTENDING 128
18 #define PKT_ERROR(pkt, errmsg) \
20 cfpkt_priv(pkt)->erronous = true; \
21 skb_reset_tail_pointer(&pkt->skb); \
51 static inline bool is_erronous(
struct cfpkt *pkt)
53 return cfpkt_priv(pkt)->erronous;
56 static inline struct sk_buff *pkt_to_skb(
struct cfpkt *pkt)
68 struct cfpkt *pkt = skb_to_pkt(nativepkt);
69 cfpkt_priv(pkt)->erronous =
false;
80 static struct cfpkt *cfpkt_create_pfx(
u16 len,
u16 pfx)
92 skb_reserve(skb, pfx);
93 return skb_to_pkt(skb);
103 struct sk_buff *skb = pkt_to_skb(pkt);
109 struct sk_buff *skb = pkt_to_skb(pkt);
115 struct sk_buff *skb = pkt_to_skb(pkt);
116 if (skb_headlen(skb) >= len) {
126 struct sk_buff *skb = pkt_to_skb(pkt);
132 PKT_ERROR(pkt,
"read beyond end of packet\n");
136 if (
unlikely(len > skb_headlen(skb))) {
137 if (
unlikely(skb_linearize(skb) != 0)) {
152 struct sk_buff *skb = pkt_to_skb(pkt);
158 if (
unlikely(skb_linearize(skb) != 0)) {
162 if (
unlikely(skb->
data + len > skb_tail_pointer(skb))) {
163 PKT_ERROR(pkt,
"read beyond end of packet\n");
166 from = skb_tail_pointer(skb) -
len;
179 struct sk_buff *skb = pkt_to_skb(pkt);
191 if (
unlikely(skb_tailroom(skb) < len)) {
199 if (
unlikely((addlen > 0) || skb_cloned(skb) || skb_shared(skb))) {
211 if (lastskb != skb) {
212 pr_warn(
"Packet is non-linear\n");
232 struct sk_buff *skb = pkt_to_skb(pkt);
239 if (
unlikely(skb_headroom(skb) < len)) {
264 struct sk_buff *skb = pkt_to_skb(pkt);
287 struct sk_buff *skb = pkt_to_skb(pkt);
293 if (
likely(len <= skb->len)) {
304 PKT_ERROR(pkt,
"skb_pad_trail failed\n");
310 struct cfpkt *addpkt,
315 u16 addlen = skb_headlen(add);
320 if (
unlikely(is_erronous(dstpkt) || is_erronous(addpkt))) {
323 if (expectlen > addlen)
324 neededtailspace = expectlen;
326 neededtailspace = addlen;
328 if (dst->
tail + neededtailspace > dst->
end) {
330 struct cfpkt *tmppkt;
331 dstlen = skb_headlen(dst);
332 createlen = dstlen + neededtailspace;
336 tmp = pkt_to_skb(tmppkt);
337 skb_set_tail_pointer(tmp, dstlen);
343 memcpy(skb_tail_pointer(dst), add->
data, skb_headlen(add));
347 return skb_to_pkt(dst);
353 struct sk_buff *skb = pkt_to_skb(pkt);
354 struct cfpkt *tmppkt;
356 u16 len2nd = skb_tail_pointer(skb) -
split;
361 if (skb->
data + pos > skb_tail_pointer(skb)) {
362 PKT_ERROR(pkt,
"trying to split beyond end of packet\n");
371 skb2 = pkt_to_skb(tmppkt);
378 skb_set_tail_pointer(skb, pos);
382 skb2->
tail += len2nd;
385 return skb_to_pkt(skb2);
390 return cfpkt_priv(pkt)->erronous;
401 pkt_to_skb(pkt)->priority =
prio;