Skip to content

Commit daa5cdc

Browse files
dsahernborkmann
authored andcommitted
net: Refactor xdp_convert_buff_to_frame
Move the guts of xdp_convert_buff_to_frame to a new helper, xdp_update_frame_from_buff so it can be reused removing code duplication Suggested-by: Jesper Dangaard Brouer <brouer@redhat.com> Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: David Ahern <dsahern@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Jesper Dangaard Brouer <brouer@redhat.com> Link: https://lore.kernel.org/bpf/90a68c283d7ebeb48924934c9b7ac79492300472.1594734381.git.lorenzo@kernel.org
1 parent 9b74ebb commit daa5cdc

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

‎include/net/xdp.h‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,39 +121,48 @@ void xdp_convert_frame_to_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
121121
xdp->frame_sz = frame->frame_sz;
122122
}
123123

124-
/* Convert xdp_buff to xdp_frame */
125124
static inline
126-
struct xdp_frame *xdp_convert_buff_to_frame(struct xdp_buff *xdp)
125+
int xdp_update_frame_from_buff(struct xdp_buff *xdp,
126+
struct xdp_frame *xdp_frame)
127127
{
128-
struct xdp_frame *xdp_frame;
129-
int metasize;
130-
int headroom;
131-
132-
if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL)
133-
return xdp_convert_zc_to_xdp_frame(xdp);
128+
int metasize, headroom;
134129

135130
/* Assure headroom is available for storing info */
136131
headroom = xdp->data - xdp->data_hard_start;
137132
metasize = xdp->data - xdp->data_meta;
138133
metasize = metasize > 0 ? metasize : 0;
139134
if (unlikely((headroom - metasize) < sizeof(*xdp_frame)))
140-
return NULL;
135+
return -ENOSPC;
141136

142137
/* Catch if driver didn't reserve tailroom for skb_shared_info */
143138
if (unlikely(xdp->data_end > xdp_data_hard_end(xdp))) {
144139
XDP_WARN("Driver BUG: missing reserved tailroom");
145-
return NULL;
140+
return -ENOSPC;
146141
}
147142

148-
/* Store info in top of packet */
149-
xdp_frame = xdp->data_hard_start;
150-
151143
xdp_frame->data = xdp->data;
152144
xdp_frame->len = xdp->data_end - xdp->data;
153145
xdp_frame->headroom = headroom - sizeof(*xdp_frame);
154146
xdp_frame->metasize = metasize;
155147
xdp_frame->frame_sz = xdp->frame_sz;
156148

149+
return 0;
150+
}
151+
152+
/* Convert xdp_buff to xdp_frame */
153+
static inline
154+
struct xdp_frame *xdp_convert_buff_to_frame(struct xdp_buff *xdp)
155+
{
156+
struct xdp_frame *xdp_frame;
157+
158+
if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL)
159+
return xdp_convert_zc_to_xdp_frame(xdp);
160+
161+
/* Store info in top of packet */
162+
xdp_frame = xdp->data_hard_start;
163+
if (unlikely(xdp_update_frame_from_buff(xdp, xdp_frame) < 0))
164+
return NULL;
165+
157166
/* rxq only valid until napi_schedule ends, convert to xdp_mem_info */
158167
xdp_frame->mem = xdp->rxq->mem;
159168

0 commit comments

Comments
 (0)