summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2021-05-27 22:20:00 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2021-05-27 22:20:00 +0200
commit710f891c8a6116f520948f5cf448489947fb7d78 (patch)
tree3110340236474245b590d75103383c8bf89de631
parentdc3971e3f5e284dd38e0a434725e7f451baef55c (diff)
pktbuff: add __pktb_setup()HEADmaster
Add private helper function to set up the pkt_buff object. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/extra/pktbuff.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/extra/pktbuff.c b/src/extra/pktbuff.c
index 6dd0ca9..9bdc6bd 100644
--- a/src/extra/pktbuff.c
+++ b/src/extra/pktbuff.c
@@ -29,6 +29,35 @@
* @{
*/
+static int __pktb_setup(int family, struct pkt_buff *pktb)
+{
+ struct ethhdr *ethhdr;
+
+ switch (family) {
+ case AF_INET:
+ case AF_INET6:
+ pktb->network_header = pktb->data;
+ break;
+ case AF_BRIDGE:
+ ethhdr = (struct ethhdr *)pktb->data;
+ pktb->mac_header = pktb->data;
+
+ switch(ethhdr->h_proto) {
+ case ETH_P_IP:
+ case ETH_P_IPV6:
+ pktb->network_header = pktb->data + ETH_HLEN;
+ break;
+ default:
+ /* This protocol is unsupported. */
+ errno = EPROTONOSUPPORT;
+ return -1;
+ }
+ break;
+ }
+
+ return 0;
+}
+
/**
* pktb_alloc - allocate a new packet buffer
* \param family Indicate what family. Currently supported families are
@@ -52,7 +81,6 @@ EXPORT_SYMBOL
struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra)
{
struct pkt_buff *pktb;
- struct ethhdr *ethhdr;
void *pkt_data;
pktb = calloc(1, sizeof(struct pkt_buff) + len + extra);
@@ -68,28 +96,11 @@ struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra)
pktb->data = pkt_data;
- switch(family) {
- case AF_INET:
- case AF_INET6:
- pktb->network_header = pktb->data;
- break;
- case AF_BRIDGE:
- ethhdr = (struct ethhdr *)pktb->data;
- pktb->mac_header = pktb->data;
-
- switch(ethhdr->h_proto) {
- case ETH_P_IP:
- case ETH_P_IPV6:
- pktb->network_header = pktb->data + ETH_HLEN;
- break;
- default:
- /* This protocol is unsupported. */
- errno = EPROTONOSUPPORT;
- free(pktb);
- return NULL;
- }
- break;
+ if (__pktb_setup(family, pktb) < 0) {
+ free(pktb);
+ return NULL;
}
+
return pktb;
}