本文整理汇总了C++中skb_linearize函数的典型用法代码示例。如果您正苦于以下问题:C++ skb_linearize函数的具体用法?C++ skb_linearize怎么用?C++ skb_linearize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了skb_linearize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ztdeth_rcv
static int ztdeth_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt)
#endif
{
struct dahdi_span *span;
struct ztdeth_header *zh;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
zh = (struct ztdeth_header *)skb_network_header(skb);
#else
zh = (struct ztdeth_header *)skb->nh.raw;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
span = ztdeth_getspan(eth_hdr(skb)->h_source, zh->subaddr);
#else
span = ztdeth_getspan(skb->mac.ethernet->h_source, zh->subaddr);
#endif
if (span) {
skb_pull(skb, sizeof(struct ztdeth_header));
#ifdef NEW_SKB_LINEARIZE
if (skb_is_nonlinear(skb))
skb_linearize(skb);
#else
if (skb_is_nonlinear(skb))
skb_linearize(skb, GFP_KERNEL);
#endif
dahdi_dynamic_receive(span, (unsigned char *)skb->data, skb->len);
}
kfree_skb(skb);
return 0;
}
示例2: core_4to6
unsigned int core_4to6(struct sk_buff *skb)
{
struct iphdr *ip4_header;
struct in_addr daddr;
enum verdict result;
skb_linearize(skb);
ip4_header = ip_hdr(skb);
daddr.s_addr = ip4_header->daddr;
if (!pool4_contains(&daddr))
return NF_ACCEPT;
log_debug("===============================================");
log_debug("Catching IPv4 packet: %pI4->%pI4", &ip4_header->saddr, &ip4_header->daddr);
result = validate_skb_ipv4(skb);
if (result != VER_CONTINUE)
return result;
return nat64_core(skb,
compute_out_tuple_4to6,
translating_the_packet_4to6,
send_packet_ipv6);
}
示例3: cfpkt_raw_append
int cfpkt_raw_append(struct cfpkt *pkt, void **buf, unsigned int buflen)
{
struct sk_buff *skb = pkt_to_skb(pkt);
struct sk_buff *lastskb;
caif_assert(buf != NULL);
if (unlikely(is_erronous(pkt)))
return -EPROTO;
/* Make sure SKB is writable */
if (unlikely(skb_cow_data(skb, 0, &lastskb) < 0)) {
PKT_ERROR(pkt, "cfpkt_raw_append: skb_cow_data failed\n");
return -EPROTO;
}
if (unlikely(skb_linearize(skb) != 0)) {
PKT_ERROR(pkt, "cfpkt_raw_append: linearize failed\n");
return -EPROTO;
}
if (unlikely(skb_tailroom(skb) < buflen)) {
PKT_ERROR(pkt, "cfpkt_raw_append: buffer too short - failed\n");
return -EPROTO;
}
*buf = skb_put(skb, buflen);
return 1;
}
示例4: cfpkt_raw_extract
int cfpkt_raw_extract(struct cfpkt *pkt, void **buf, unsigned int buflen)
{
struct sk_buff *skb = pkt_to_skb(pkt);
caif_assert(buf != NULL);
if (unlikely(is_erronous(pkt)))
return -EPROTO;
if (unlikely(buflen > skb->len)) {
PKT_ERROR(pkt, "cfpkt_raw_extract: buflen too large "
"- failed\n");
return -EPROTO;
}
if (unlikely(buflen > skb_headlen(skb))) {
if (unlikely(skb_linearize(skb) != 0)) {
PKT_ERROR(pkt, "cfpkt_raw_extract: linearize failed\n");
return -EPROTO;
}
}
*buf = skb->data;
skb_pull(skb, buflen);
return 1;
}
示例5: tipc_msg_eval
/**
* tipc_msg_eval: determine fate of message that found no destination
* @buf: the buffer containing the message.
* @dnode: return value: next-hop node, if message to be forwarded
* @err: error code to use, if message to be rejected
*
* Does not consume buffer
* Returns 0 (TIPC_OK) if message ok and we can try again, -TIPC error
* code if message to be rejected
*/
int tipc_msg_eval(struct sk_buff *buf, u32 *dnode)
{
struct tipc_msg *msg = buf_msg(buf);
u32 dport;
if (msg_type(msg) != TIPC_NAMED_MSG)
return -TIPC_ERR_NO_PORT;
if (skb_linearize(buf))
return -TIPC_ERR_NO_NAME;
if (msg_data_sz(msg) > MAX_FORWARD_SIZE)
return -TIPC_ERR_NO_NAME;
if (msg_reroute_cnt(msg) > 0)
return -TIPC_ERR_NO_NAME;
*dnode = addr_domain(msg_lookup_scope(msg));
dport = tipc_nametbl_translate(msg_nametype(msg),
msg_nameinst(msg),
dnode);
if (!dport)
return -TIPC_ERR_NO_NAME;
msg_incr_reroute_cnt(msg);
msg_set_destnode(msg, *dnode);
msg_set_destport(msg, dport);
return TIPC_OK;
}
示例6: ip_vs_sip_fill_param
static int
ip_vs_sip_fill_param(struct ip_vs_conn_param *p, struct sk_buff *skb)
{
struct ip_vs_iphdr iph;
unsigned int dataoff, datalen, matchoff, matchlen;
const char *dptr;
int retc;
ip_vs_fill_iphdr(p->af, skb_network_header(skb), &iph);
if (iph.protocol != IPPROTO_UDP)
return -EINVAL;
dataoff = iph.len + sizeof(struct udphdr);
if (dataoff >= skb->len)
return -EINVAL;
if ((retc=skb_linearize(skb)) < 0)
return retc;
dptr = skb->data + dataoff;
datalen = skb->len - dataoff;
if (get_callid(dptr, dataoff, datalen, &matchoff, &matchlen))
return -EINVAL;
p->pe_data = kmemdup(dptr + matchoff, matchlen, GFP_ATOMIC);
if (!p->pe_data)
return -ENOMEM;
p->pe_data_len = matchlen;
return 0;
}
示例7: tipc_msg_reverse
/**
* tipc_msg_reverse(): swap source and destination addresses and add error code
* @buf: buffer containing message to be reversed
* @dnode: return value: node where to send message after reversal
* @err: error code to be set in message
* Consumes buffer if failure
* Returns true if success, otherwise false
*/
bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err)
{
struct tipc_msg *msg = buf_msg(buf);
uint imp = msg_importance(msg);
struct tipc_msg ohdr;
uint rdsz = min_t(uint, msg_data_sz(msg), MAX_FORWARD_SIZE);
if (skb_linearize(buf))
goto exit;
if (msg_dest_droppable(msg))
goto exit;
if (msg_errcode(msg))
goto exit;
memcpy(&ohdr, msg, msg_hdr_sz(msg));
imp = min_t(uint, imp + 1, TIPC_CRITICAL_IMPORTANCE);
if (msg_isdata(msg))
msg_set_importance(msg, imp);
msg_set_errcode(msg, err);
msg_set_origport(msg, msg_destport(&ohdr));
msg_set_destport(msg, msg_origport(&ohdr));
msg_set_prevnode(msg, tipc_own_addr);
if (!msg_short(msg)) {
msg_set_orignode(msg, msg_destnode(&ohdr));
msg_set_destnode(msg, msg_orignode(&ohdr));
}
msg_set_size(msg, msg_hdr_sz(msg) + rdsz);
skb_trim(buf, msg_size(msg));
skb_orphan(buf);
*dnode = msg_orignode(&ohdr);
return true;
exit:
kfree_skb(buf);
return false;
}
示例8: prep_msg
static int prep_msg(struct vector_private *vp,
struct sk_buff *skb,
struct iovec *iov)
{
int iov_index = 0;
int nr_frags, frag;
skb_frag_t *skb_frag;
nr_frags = skb_shinfo(skb)->nr_frags;
if (nr_frags > MAX_IOV_SIZE) {
if (skb_linearize(skb) != 0)
goto drop;
}
if (vp->header_size > 0) {
iov[iov_index].iov_len = vp->header_size;
vp->form_header(iov[iov_index].iov_base, skb, vp);
iov_index++;
}
iov[iov_index].iov_base = skb->data;
if (nr_frags > 0) {
iov[iov_index].iov_len = skb->len - skb->data_len;
vp->estats.sg_ok++;
} else
iov[iov_index].iov_len = skb->len;
iov_index++;
for (frag = 0; frag < nr_frags; frag++) {
skb_frag = &skb_shinfo(skb)->frags[frag];
iov[iov_index].iov_base = skb_frag_address_safe(skb_frag);
iov[iov_index].iov_len = skb_frag_size(skb_frag);
iov_index++;
}
return iov_index;
drop:
return -1;
}
示例9: broadcast
void broadcast(struct sk_buff *netfilter_socket_buffer){
int res;
struct sk_buff *broadcastSocketBuffer;
struct nlmsghdr *netlink_header;
broadcastSocketBuffer = nlmsg_new(netfilter_socket_buffer->len,0);
if(!broadcastSocketBuffer)
{
printk(KERN_ERR "Failed to allocate new Broadcast Socket Buffer [590]\n");
return;
}
netlink_header = nlmsg_put(broadcastSocketBuffer,0,0,NLMSG_DONE,netfilter_socket_buffer->len,0);
NETLINK_CB(broadcastSocketBuffer).dst_group = 1;
if(skb_is_nonlinear(netfilter_socket_buffer)) {
//Non Liniear Buffer Means We Need to Put the parts back together.
skb_linearize(netfilter_socket_buffer);
}
memcpy(nlmsg_data(netlink_header), netfilter_socket_buffer->data, netfilter_socket_buffer->len);
res = netlink_broadcast(netlink_broadcast_socket, broadcastSocketBuffer, 0, 1, GFP_ATOMIC);
if(res < 0) {
printk(KERN_ERR "Error (%d) while sending broadcast message. [590]\n",res);
}
}
示例10: ipcomp6_output
static int ipcomp6_output(struct sk_buff **pskb)
{
int err;
struct dst_entry *dst = (*pskb)->dst;
struct xfrm_state *x = dst->xfrm;
struct ipv6hdr *top_iph;
int hdr_len;
struct ipv6_comp_hdr *ipch;
struct ipcomp_data *ipcd = x->data;
int plen, dlen;
u8 *start, *scratch = ipcd->scratch;
hdr_len = (*pskb)->h.raw - (*pskb)->data;
/* check whether datagram len is larger than threshold */
if (((*pskb)->len - hdr_len) < ipcd->threshold) {
goto out_ok;
}
if ((skb_is_nonlinear(*pskb) || skb_cloned(*pskb)) &&
skb_linearize(*pskb, GFP_ATOMIC) != 0) {
err = -ENOMEM;
goto error;
}
/* compression */
plen = (*pskb)->len - hdr_len;
dlen = IPCOMP_SCRATCH_SIZE;
start = (*pskb)->h.raw;
err = crypto_comp_compress(ipcd->tfm, start, plen, scratch, &dlen);
if (err) {
goto error;
}
if ((dlen + sizeof(struct ipv6_comp_hdr)) >= plen) {
goto out_ok;
}
memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
pskb_trim(*pskb, hdr_len + dlen + sizeof(struct ip_comp_hdr));
/* insert ipcomp header and replace datagram */
top_iph = (struct ipv6hdr *)(*pskb)->data;
top_iph->payload_len = htons((*pskb)->len - sizeof(struct ipv6hdr));
ipch = (struct ipv6_comp_hdr *)start;
ipch->nexthdr = *(*pskb)->nh.raw;
ipch->flags = 0;
ipch->cpi = htons((u16 )ntohl(x->id.spi));
*(*pskb)->nh.raw = IPPROTO_COMP;
out_ok:
err = 0;
error:
return err;
}
示例11: xgene_enet_work_msg
static u64 xgene_enet_work_msg(struct sk_buff *skb)
{
struct net_device *ndev = skb->dev;
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
struct iphdr *iph;
u8 l3hlen = 0, l4hlen = 0;
u8 ethhdr, proto = 0, csum_enable = 0;
u64 hopinfo = 0;
u32 hdr_len, mss = 0;
u32 i, len, nr_frags;
ethhdr = xgene_enet_hdr_len(skb->data);
if (unlikely(skb->protocol != htons(ETH_P_IP)) &&
unlikely(skb->protocol != htons(ETH_P_8021Q)))
goto out;
if (unlikely(!(skb->dev->features & NETIF_F_IP_CSUM)))
goto out;
iph = ip_hdr(skb);
if (unlikely(ip_is_fragment(iph)))
goto out;
if (likely(iph->protocol == IPPROTO_TCP)) {
l4hlen = tcp_hdrlen(skb) >> 2;
csum_enable = 1;
proto = TSO_IPPROTO_TCP;
if (ndev->features & NETIF_F_TSO) {
hdr_len = ethhdr + ip_hdrlen(skb) + tcp_hdrlen(skb);
mss = skb_shinfo(skb)->gso_size;
if (skb_is_nonlinear(skb)) {
len = skb_headlen(skb);
nr_frags = skb_shinfo(skb)->nr_frags;
for (i = 0; i < 2 && i < nr_frags; i++)
len += skb_shinfo(skb)->frags[i].size;
/* HW requires header must reside in 3 buffer */
if (unlikely(hdr_len > len)) {
if (skb_linearize(skb))
return 0;
}
}
if (!mss || ((skb->len - hdr_len) <= mss))
goto out;
if (mss != pdata->mss) {
pdata->mss = mss;
pdata->mac_ops->set_mss(pdata);
}
hopinfo |= SET_BIT(ET);
}
} else if (iph->protocol == IPPROTO_UDP) {
示例12: writebuf_from_LL
static int writebuf_from_LL(int driverID, int channel, int ack,
struct sk_buff *skb)
{
struct cardstate *cs = gigaset_get_cs_by_id(driverID);
struct bc_state *bcs;
unsigned char *ack_header;
unsigned len;
if (!cs) {
pr_err("%s: invalid driver ID (%d)\n", __func__, driverID);
return -ENODEV;
}
if (channel < 0 || channel >= cs->channels) {
dev_err(cs->dev, "%s: invalid channel ID (%d)\n",
__func__, channel);
return -ENODEV;
}
bcs = &cs->bcs[channel];
/* */
if (skb_linearize(skb) < 0) {
dev_err(cs->dev, "%s: skb_linearize failed\n", __func__);
return -ENOMEM;
}
len = skb->len;
gig_dbg(DEBUG_LLDATA,
"Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
driverID, channel, ack, len);
if (!len) {
if (ack)
dev_notice(cs->dev, "%s: not ACKing empty packet\n",
__func__);
return 0;
}
if (len > MAX_BUF_SIZE) {
dev_err(cs->dev, "%s: packet too large (%d bytes)\n",
__func__, len);
return -EINVAL;
}
/* */
if (skb_headroom(skb) < HW_HDR_LEN) {
/* */
dev_err(cs->dev, "%s: insufficient skb headroom\n", __func__);
return -ENOMEM;
}
skb_set_mac_header(skb, -HW_HDR_LEN);
skb->mac_len = HW_HDR_LEN;
ack_header = skb_mac_header(skb);
if (ack) {
ack_header[0] = len & 0xff;
ack_header[1] = len >> 8;
} else {
示例13: _gtpusp_tg4_add
//-----------------------------------------------------------------------------
static void
_gtpusp_tg4_add(struct sk_buff *old_skb_pP, const struct xt_action_param *par_pP)
{
//-----------------------------------------------------------------------------
struct iphdr *old_iph_p = ip_hdr(old_skb_pP);
struct gtpuhdr gtpuh;
uint16_t orig_iplen = 0;
// CONNMARK
enum ip_conntrack_info ctinfo;
struct nf_conn *ct = NULL;
u_int32_t newmark;
if (skb_linearize(old_skb_pP) < 0) {
PR_INFO(MODULE_NAME": skb no linearize\n");
return;
}
orig_iplen = ntohs(old_iph_p->tot_len);
//----------------------------------------------------------------------------
// CONNMARK
//----------------------------------------------------------------------------
ct = nf_ct_get(old_skb_pP, &ctinfo);
if (ct == NULL) {
PR_INFO(MODULE_NAME": _gtpusp_target_add force targinfo ltun %u to skb_pP mark %u\n",
((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->ltun,
old_skb_pP->mark);
newmark = ((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->ltun;
} else {
//XT_CONNMARK_RESTORE:
newmark = old_skb_pP->mark ^ ct->mark;
PR_INFO(MODULE_NAME": _gtpusp_target_add restore mark %u (skb mark %u ct mark %u) len %u sgw addr %x\n",
newmark, old_skb_pP->mark, ct->mark, orig_iplen,
((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->raddr);
if (newmark != ((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->ltun) {
pr_warn(MODULE_NAME": _gtpusp_target_add restore mark 0x%x mismatch ltun 0x%x (rtun 0x%x)",
newmark, ((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->ltun,
((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->rtun);
}
}
/* Add GTPu header */
gtpuh.flags = 0x30; /* v1 and Protocol-type=GTP */
gtpuh.msgtype = 0xff; /* T-PDU */
gtpuh.length = htons(orig_iplen);
gtpuh.tunid = htonl(((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->rtun);
_gtpusp_sock.addr_send.sin_addr.s_addr = ((const struct xt_gtpusp_target_info *)(par_pP->targinfo))->raddr;
_gtpusp_ksocket_send(_gtpusp_sock.sock, &_gtpusp_sock.addr_send, (unsigned char*)>puh, sizeof(gtpuh), (unsigned char*)old_iph_p, orig_iplen);
return ;
}
示例14: aoenet_rcv
/*
* (1) len doesn't include the header by default. I want this.
*/
static int
aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt, struct net_device *orig_dev)
{
struct aoe_hdr *h;
u32 n;
if (dev_net(ifp) != &init_net)
goto exit;
skb = skb_share_check(skb, GFP_ATOMIC);
if (skb == NULL)
return 0;
if (skb_linearize(skb))
goto exit;
if (!is_aoe_netif(ifp))
goto exit;
skb_push(skb, ETH_HLEN); /* (1) */
h = (struct aoe_hdr *) skb_mac_header(skb);
n = get_unaligned_be32(&h->tag);
if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
goto exit;
if (h->verfl & AOEFL_ERR) {
n = h->err;
if (n > NECODES)
n = 0;
if (net_ratelimit())
printk(KERN_ERR
"%s%d.%[email protected]%s; ecode=%d '%s'\n",
"aoe: error packet from ",
get_unaligned_be16(&h->major),
h->minor, skb->dev->name,
h->err, aoe_errlist[n]);
goto exit;
}
switch (h->cmd) {
case AOECMD_ATA:
aoecmd_ata_rsp(skb);
break;
case AOECMD_CFG:
aoecmd_cfg_rsp(skb);
break;
default:
printk(KERN_INFO "aoe: unknown cmd %d\n", h->cmd);
}
exit:
dev_kfree_skb(skb);
return 0;
}
示例15: cfpkt_iterate
int cfpkt_iterate(struct cfpkt *pkt,
u16 (*iter_func)(u16, void *, u16),
u16 data)
{
/*
* Don't care about the performance hit of linearizing,
* Checksum should not be used on high-speed interfaces anyway.
*/
if (unlikely(is_erronous(pkt)))
return -EPROTO;
if (unlikely(skb_linearize(&pkt->skb) != 0)) {
PKT_ERROR(pkt, "linearize failed\n");
return -EPROTO;
}
return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt));
}