本文整理汇总了C++中skb_shared函数的典型用法代码示例。如果您正苦于以下问题:C++ skb_shared函数的具体用法?C++ skb_shared怎么用?C++ skb_shared使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了skb_shared函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ebt_target_snat
static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
const struct net_device *in, const struct net_device *out,
const void *data, unsigned int datalen)
{
struct ebt_nat_info *info = (struct ebt_nat_info *) data;
if (skb_shared(*pskb) || skb_cloned(*pskb)) {
struct sk_buff *nskb;
nskb = skb_copy(*pskb, GFP_ATOMIC);
if (!nskb)
return NF_DROP;
if ((*pskb)->sk)
skb_set_owner_w(nskb, (*pskb)->sk);
kfree_skb(*pskb);
*pskb = nskb;
}
memcpy(eth_hdr(*pskb)->h_source, info->mac, ETH_ALEN);
if (!(info->target & NAT_ARP_BIT) &&
eth_hdr(*pskb)->h_proto == htons(ETH_P_ARP)) {
struct arphdr _ah, *ap;
ap = skb_header_pointer(*pskb, 0, sizeof(_ah), &_ah);
if (ap == NULL)
return EBT_DROP;
if (ap->ar_hln != ETH_ALEN)
goto out;
if (skb_store_bits(*pskb, sizeof(_ah), info->mac,ETH_ALEN))
return EBT_DROP;
}
out:
return info->target | ~EBT_VERDICT_BITS;
}
示例2: __gmac_recv
/**
* @brief Protocol drivers Receive function
*
* @param skb
* @param dev
* @param type
* @param orig_dev
*
* @return int
*/
int
__gmac_recv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *type, struct net_device *orig_dev)
{
athhdr_t *ath;
ethhdr_t *eth;
hif_gmac_node_t *node = NULL;
a_uint32_t idx = 0;
hif_gmac_softc_t *sc = __gmac_pkt.af_packet_priv;
if (skb_shared(skb))
skb = skb_unshare(skb, GFP_ATOMIC);
eth = eth_hdr(skb); /* Linux specific */
ath = ath_hdr(skb);
/* printk("%s\n",__func__); */
/**
* Query MAC Table
*/
node = __gmac_qry_tbl(eth->h_source);
idx = ((node->hdr.ath.type.proto == ath->type.proto) &&
chk_ucast(eth->h_dest));
sc->recv_fn[idx](skb, node, ath->type.proto);
return 0;
}
示例3: osif_send_to_nss
void
osif_send_to_nss(os_if_t osif, struct sk_buff *skb, int nwifi)
{
struct net_device *dev = OSIF_TO_NETDEV(osif);
osif_dev *osifp = (osif_dev *) osif;
if(!osifp->nssctx){
goto out;
}
skb->next =NULL;
if (skb_shared(skb)){
goto out;
}
if (nwifi) {
if (nss_tx_virt_if_rx_nwifibuf(osifp->nssctx, skb)) {
goto out ;
}
} else {
if(nss_tx_virt_if_rxbuf(osifp->nssctx, skb)){
goto out;
}
}
return ;
out:
if (nwifi) {
transcap_nwifi_to_8023(skb);
skb->protocol = eth_type_trans(skb, dev);
}
skb->dev = dev;
netif_rx(skb);
return ;
}
示例4: skb_recycle_check
/**
* skb_recycle_check - check if skb can be reused for receive
* @skb: buffer
* @skb_size: minimum receive buffer size
*
* Checks that the skb passed in is not shared or cloned, and
* that it is linear and its head portion at least as large as
* skb_size so that it can be recycled as a receive buffer.
* If these conditions are met, this function does any necessary
* reference count dropping and cleans up the skbuff as if it
* just came from __alloc_skb().
*/
bool skb_recycle_check(struct sk_buff *skb, int skb_size)
{
struct skb_shared_info *shinfo;
// if (irqs_disabled())
// return false;
if (skb_is_nonlinear(skb) || skb->fclone != SKB_FCLONE_UNAVAILABLE)
return false;
skb_size = SKB_DATA_ALIGN(skb_size + NET_SKB_PAD);
if (skb_end_pointer(skb) - skb->head < skb_size)
return false;
if (skb_shared(skb) || skb_cloned(skb))
return false;
skb_release_head_state(skb);
shinfo = skb_shinfo(skb);
memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
atomic_set(&shinfo->dataref, 1);
memset(skb, 0, offsetof(struct sk_buff, tail));
skb->data = skb->head + NET_SKB_PAD;
skb_reset_tail_pointer(skb);
return true;
} EXPORT_SYMBOL(skb_recycle_check);
示例5:
static struct sock *run_bpf(struct sock_reuseport *reuse, u16 socks,
struct bpf_prog *prog, struct sk_buff *skb,
int hdr_len)
{
struct sk_buff *nskb = NULL;
u32 index;
if (skb_shared(skb)) {
nskb = skb_clone(skb, GFP_ATOMIC);
if (!nskb)
return NULL;
skb = nskb;
}
/* temporarily advance data past protocol header */
if (!pskb_pull(skb, hdr_len)) {
kfree_skb(nskb);
return NULL;
}
index = bpf_prog_run_save_cb(prog, skb);
__skb_push(skb, hdr_len);
consume_skb(nskb);
if (index >= socks)
return NULL;
return reuse->socks[index];
}
示例6: ip_vs_make_skb_writable
int ip_vs_make_skb_writable(struct sk_buff **pskb, int writable_len)
{
struct sk_buff *skb = *pskb;
/* skb is already used, better copy skb and its payload */
if (unlikely(skb_shared(skb) || skb->sk))
goto copy_skb;
/* skb data is already used, copy it */
if (unlikely(skb_cloned(skb)))
goto copy_data;
return pskb_may_pull(skb, writable_len);
copy_data:
if (unlikely(writable_len > skb->len))
return 0;
return !pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
copy_skb:
if (unlikely(writable_len > skb->len))
return 0;
skb = skb_copy(skb, GFP_ATOMIC);
if (!skb)
return 0;
BUG_ON(skb_is_nonlinear(skb));
/* Rest of kernel will get very unhappy if we pass it a
suddenly-orphaned skbuff */
if ((*pskb)->sk)
skb_set_owner_w(skb, (*pskb)->sk);
kfree_skb(*pskb);
*pskb = skb;
return 1;
}
示例7: genl_exec
int genl_exec(genl_exec_func_t func, void *data)
{
int ret;
mutex_lock(&genl_exec_lock);
init_completion(&done);
skb_get(genlmsg_skb);
genlmsg_put(genlmsg_skb, 0, 0, &genl_exec_family,
NLM_F_REQUEST, GENL_EXEC_RUN);
genl_exec_function = func;
genl_exec_data = data;
/* There is no need to send msg to current namespace. */
ret = genlmsg_unicast(&init_net, genlmsg_skb, 0);
if (!ret) {
wait_for_completion(&done);
ret = genl_exec_function_ret;
} else {
pr_err("genl_exec send error %d\n", ret);
}
/* Wait for genetlink to kfree skb. */
while (skb_shared(genlmsg_skb))
cpu_relax();
genlmsg_skb->data = genlmsg_skb->head;
skb_reset_tail_pointer(genlmsg_skb);
mutex_unlock(&genl_exec_lock);
return ret;
}
示例8: ERR_PTR
static struct sk_buff *skb_set_peeked(struct sk_buff *skb)
{
struct sk_buff *nskb;
if (skb->peeked)
return skb;
/* We have to unshare an skb before modifying it. */
if (!skb_shared(skb))
goto done;
nskb = skb_clone(skb, GFP_ATOMIC);
if (!nskb)
return ERR_PTR(-ENOMEM);
skb->prev->next = nskb;
skb->next->prev = nskb;
nskb->prev = skb->prev;
nskb->next = skb->next;
consume_skb(skb);
skb = nskb;
done:
skb->peeked = 1;
return skb;
}
示例9: ethertap_rx_skb
static __inline__ int ethertap_rx_skb(struct sk_buff *skb, struct net_device *dev)
{
struct net_local *lp = (struct net_local *)dev->priv;
#ifdef CONFIG_ETHERTAP_MC
struct ethhdr *eth = (struct ethhdr*)(skb->data + 2);
#endif
int len = skb->len;
if (len < 16) {
printk(KERN_DEBUG "%s : rx len = %d\n", dev->name, len);
kfree_skb(skb);
return -EINVAL;
}
if (NETLINK_CREDS(skb)->uid) {
printk(KERN_INFO "%s : user %d\n", dev->name, NETLINK_CREDS(skb)->uid);
kfree_skb(skb);
return -EPERM;
}
#ifdef CONFIG_ETHERTAP_MC
if (!(dev->flags&(IFF_NOARP|IFF_PROMISC))) {
int drop = 0;
if (eth->h_dest[0]&1) {
if (!(ethertap_mc_hash(eth->h_dest)&lp->groups))
drop = 1;
} else if (memcmp(eth->h_dest, dev->dev_addr, 6) != 0)
drop = 1;
if (drop) {
if (ethertap_debug > 3)
printk(KERN_DEBUG "%s : not for us\n", dev->name);
kfree_skb(skb);
return -EINVAL;
}
}
#endif
if (skb_shared(skb)) {
struct sk_buff *skb2 = skb;
skb = skb_clone(skb, GFP_KERNEL); /* Clone the buffer */
if (skb==NULL) {
kfree_skb(skb2);
return -ENOBUFS;
}
kfree_skb(skb2);
} else
skb_orphan(skb);
skb_pull(skb, 2);
skb->dev = dev;
skb->protocol=eth_type_trans(skb,dev);
memset(skb->cb, 0, sizeof(skb->cb));
lp->stats.rx_packets++;
lp->stats.rx_bytes+=len;
netif_rx(skb);
dev->last_rx = jiffies;
return len;
}
示例10: offsetof
struct sk_buff *hieth_platdev_alloc_skb(struct hieth_netdev_local *ld)
{
struct sk_buff *skb;
int i;
skb = ld->rx_pool.sk_pool[ld->rx_pool.next_free_skb++];
if (ld->rx_pool.next_free_skb == CONFIG_HIETH_MAX_RX_POOLS)
ld->rx_pool.next_free_skb = 0;
/*current skb is used by kernel or other process,find another skb*/
if (skb_shared(skb) || (atomic_read(&(skb_shinfo(skb)->dataref)) > 1)) {
for (i = 0; i < CONFIG_HIETH_MAX_RX_POOLS; i++) {
skb = ld->rx_pool.sk_pool[ld->rx_pool.next_free_skb++];
if (ld->rx_pool.next_free_skb ==
CONFIG_HIETH_MAX_RX_POOLS)
ld->rx_pool.next_free_skb = 0;
if ((skb_shared(skb) == 0) &&
(atomic_read(&(skb_shinfo(skb)->dataref)) <= 1))
break;
}
if (i == CONFIG_HIETH_MAX_RX_POOLS) {
ld->stat.rx_pool_dry_times++;
hieth_trace(7, "%ld: no free skb\n",
ld->stat.rx_pool_dry_times);
return NULL;
}
}
memset(skb, 0, offsetof(struct sk_buff, tail));
skb->data = skb->tail = skb->head;
skb->end = skb->data + (skb->truesize - sizeof(struct sk_buff));
skb->len = 0;
skb->data_len = 0;
skb->cloned = 0;
atomic_inc(&skb->users);
return skb;
}
示例11: target
static unsigned int
target(struct sk_buff **pskb,
const struct net_device *in, const struct net_device *out,
unsigned int hooknum, const struct xt_target *target,
const void *targinfo)
{
const struct arpt_mangle *mangle = targinfo;
struct arphdr *arp;
unsigned char *arpptr;
int pln, hln;
if (skb_shared(*pskb) || skb_cloned(*pskb)) {
struct sk_buff *nskb;
nskb = skb_copy(*pskb, GFP_ATOMIC);
if (!nskb)
return NF_DROP;
if ((*pskb)->sk)
skb_set_owner_w(nskb, (*pskb)->sk);
kfree_skb(*pskb);
*pskb = nskb;
}
arp = (*pskb)->nh.arph;
arpptr = (*pskb)->nh.raw + sizeof(*arp);
pln = arp->ar_pln;
hln = arp->ar_hln;
/* We assume that pln and hln were checked in the match */
if (mangle->flags & ARPT_MANGLE_SDEV) {
if (ARPT_DEV_ADDR_LEN_MAX < hln ||
(arpptr + hln > (**pskb).tail))
return NF_DROP;
memcpy(arpptr, mangle->src_devaddr, hln);
}
arpptr += hln;
if (mangle->flags & ARPT_MANGLE_SIP) {
if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
(arpptr + pln > (**pskb).tail))
return NF_DROP;
memcpy(arpptr, &mangle->u_s.src_ip, pln);
}
arpptr += pln;
if (mangle->flags & ARPT_MANGLE_TDEV) {
if (ARPT_DEV_ADDR_LEN_MAX < hln ||
(arpptr + hln > (**pskb).tail))
return NF_DROP;
memcpy(arpptr, mangle->tgt_devaddr, hln);
}
arpptr += hln;
if (mangle->flags & ARPT_MANGLE_TIP) {
if (ARPT_MANGLE_ADDR_LEN_MAX < pln ||
(arpptr + pln > (**pskb).tail))
return NF_DROP;
memcpy(arpptr, &mangle->u_t.tgt_ip, pln);
}
return mangle->target;
}
示例12: ethertap_start_xmit
static int ethertap_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct net_local *lp = (struct net_local *)dev->priv;
#ifdef CONFIG_ETHERTAP_MC
struct ethhdr *eth = (struct ethhdr*)skb->data;
#endif
if (skb_headroom(skb) < 2) {
static int once;
struct sk_buff *skb2;
if (!once) {
once = 1;
printk(KERN_DEBUG "%s: not aligned xmit by protocol %04x\n", dev->name, skb->protocol);
}
skb2 = skb_realloc_headroom(skb, 2);
dev_kfree_skb(skb);
if (skb2 == NULL)
return 0;
skb = skb2;
}
__skb_push(skb, 2);
/* Make the same thing, which loopback does. */
if (skb_shared(skb)) {
struct sk_buff *skb2 = skb;
skb = skb_clone(skb, GFP_ATOMIC); /* Clone the buffer */
if (skb==NULL) {
dev_kfree_skb(skb2);
return 0;
}
dev_kfree_skb(skb2);
}
/* ... but do not orphan it here, netlink does it in any case. */
lp->stats.tx_bytes+=skb->len;
lp->stats.tx_packets++;
#ifndef CONFIG_ETHERTAP_MC
netlink_broadcast(lp->nl, skb, 0, ~0, GFP_ATOMIC);
#else
if (dev->flags&IFF_NOARP) {
netlink_broadcast(lp->nl, skb, 0, ~0, GFP_ATOMIC);
return 0;
}
if (!(eth->h_dest[0]&1)) {
/* Unicast packet */
__u32 pid;
memcpy(&pid, eth->h_dest+2, 4);
netlink_unicast(lp->nl, skb, ntohl(pid), MSG_DONTWAIT);
} else
netlink_broadcast(lp->nl, skb, 0, ethertap_mc_hash(eth->h_dest), GFP_ATOMIC);
#endif
return 0;
}
示例13: efx_end_loopback
static int efx_end_loopback(struct efx_tx_queue *tx_queue,
struct efx_loopback_self_tests *lb_tests)
{
struct efx_nic *efx = tx_queue->efx;
struct efx_loopback_state *state = efx->loopback_selftest;
struct sk_buff *skb;
int tx_done = 0, rx_good, rx_bad;
int i, rc = 0;
if (efx_dev_registered(efx))
netif_tx_lock_bh(efx->net_dev);
/* Count the number of tx completions, and decrement the refcnt. Any
* skbs not already completed will be free'd when the queue is flushed */
for (i=0; i < state->packet_count; i++) {
skb = state->skbs[i];
if (skb && !skb_shared(skb))
++tx_done;
dev_kfree_skb_any(skb);
}
if (efx_dev_registered(efx))
netif_tx_unlock_bh(efx->net_dev);
/* Check TX completion and received packet counts */
rx_good = atomic_read(&state->rx_good);
rx_bad = atomic_read(&state->rx_bad);
if (tx_done != state->packet_count) {
/* Don't free the skbs; they will be picked up on TX
* overflow or channel teardown.
*/
EFX_ERR(efx, "TX queue %d saw only %d out of an expected %d "
"TX completion events in %s loopback test\n",
tx_queue->queue, tx_done, state->packet_count,
LOOPBACK_MODE(efx));
rc = -ETIMEDOUT;
/* Allow to fall through so we see the RX errors as well */
}
/* We may always be up to a flush away from our desired packet total */
if (rx_good != state->packet_count) {
EFX_LOG(efx, "TX queue %d saw only %d out of an expected %d "
"received packets in %s loopback test\n",
tx_queue->queue, rx_good, state->packet_count,
LOOPBACK_MODE(efx));
rc = -ETIMEDOUT;
/* Fall through */
}
/* Update loopback test structure */
lb_tests->tx_sent[tx_queue->queue] += state->packet_count;
lb_tests->tx_done[tx_queue->queue] += tx_done;
lb_tests->rx_good += rx_good;
lb_tests->rx_bad += rx_bad;
return rc;
}
示例14: imq_nf_queue
static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info,
void *data)
{
struct net_device *dev;
struct net_device_stats *stats;
struct sk_buff *skb2 = NULL;
struct Qdisc *q;
unsigned int index = skb->imq_flags&IMQ_F_IFMASK;
int ret = -1;
if (index > numdevs)
return -1;
dev = imq_devs + index;
if (!(dev->flags & IFF_UP)) {
skb->imq_flags = 0;
nf_reinject(skb, info, NF_ACCEPT);
return 0;
}
dev->last_rx = jiffies;
if (skb->destructor) {
skb2 = skb;
skb = skb_clone(skb, GFP_ATOMIC);
if (!skb)
return -1;
}
skb_push(skb, IMQ_HH_LEN(info));
skb->nf_info = info;
stats = (struct net_device_stats *)dev->priv;
stats->rx_bytes+= skb->len;
stats->rx_packets++;
spin_lock_bh(&dev->queue_lock);
q = dev->qdisc;
if (q->enqueue) {
q->enqueue(skb_get(skb), q);
if (skb_shared(skb)) {
skb->destructor = imq_skb_destructor;
kfree_skb(skb);
ret = 0;
}
}
qdisc_run(dev);
spin_unlock_bh(&dev->queue_lock);
if (skb2)
kfree_skb(ret ? skb : skb2);
return ret;
}
示例15: imq_nf_queue
static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info, unsigned queue_num, void *data)
{
struct net_device *dev;
struct net_device_stats *stats;
struct sk_buff *skb2 = NULL;
struct Qdisc *q;
unsigned int index = skb->imq_flags&IMQ_F_IFMASK;
int ret = -1;
if (index > numdevs)
return -1;
dev = imq_devs + index;
if (!(dev->flags & IFF_UP)) {
skb->imq_flags = 0;
nf_reinject(skb, info, NF_ACCEPT);
return 0;
}
dev->last_rx = jiffies;
if (skb->destructor) {
skb2 = skb;
skb = skb_clone(skb, GFP_ATOMIC);
if (!skb)
return -1;
}
skb->nf_info = info;
stats = (struct net_device_stats *)dev->priv;
stats->rx_bytes+= skb->len;
stats->rx_packets++;
spin_lock_bh(&dev->queue_lock);
q = dev->qdisc;
if (q->enqueue) {
q->enqueue(skb_get(skb), q);
if (skb_shared(skb)) {
skb->destructor = imq_skb_destructor;
kfree_skb(skb);
ret = 0;
}
}
if (spin_is_locked(&dev->_xmit_lock))
netif_schedule(dev);
else
while (!netif_queue_stopped(dev) && qdisc_restart1(dev) < 0)
/* NOTHING */;
spin_unlock_bh(&dev->queue_lock);
if (skb2)
kfree_skb(ret ? skb : skb2);
return ret;
}