source: trunk/packages/xen-3.1/xen-3.1/tools/vnet/vnet-module/skb_util.h @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 3.7 KB
Line 
1/*
2 * Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free software Foundation, Inc.,
16 * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19#ifndef _VNET_SKB_UTIL_H_
20#define _VNET_SKB_UTIL_H_
21
22#ifdef __KERNEL__
23#include <net/route.h>
24#include <linux/skbuff.h>
25
26#else
27
28#include "skbuff.h"
29
30#endif
31
32struct sk_buff;
33
34extern int skb_make_room(struct sk_buff **pskb, struct sk_buff *skb, int head_n, int tail_n);
35
36extern int skb_put_bits(const struct sk_buff *skb, int offset, void *src, int len);
37
38extern void skb_print_bits(const char *msg, struct sk_buff *skb, int offset, int n);
39
40extern void buf_print(char *buf, int n);
41
42extern void *skb_trim_tail(struct sk_buff *skb, int n);
43
44extern void print_skb_data(const char *msg, int count, struct sk_buff *skb, u8 *data, int len);
45extern void print_skb(const char *msg, int count, struct sk_buff *skb);
46
47extern void print_ethhdr(const char *msg, struct sk_buff *skb);
48extern void print_iphdr(const char *msg, struct sk_buff *skb);
49extern void print_udphdr(const char *msg, struct sk_buff *skb);
50
51/* The mac.ethernet field went away in 2.6 in favour of eth_hdr().
52 */
53#ifdef __KERNEL__
54#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
55#    define NEED_ETH_HDR
56#  endif
57#else
58#  define NEED_ETH_HDR
59#endif
60
61#ifdef NEED_ETH_HDR
62
63static inline struct ethhdr *eth_hdr(const struct sk_buff *skb)
64{
65        return (struct ethhdr *)skb->mac.raw;
66}
67
68#endif
69
70
71#ifdef __KERNEL__
72
73struct scatterlist;
74
75extern int skb_scatterlist(struct sk_buff *skb, struct scatterlist *sg,
76                           int *sg_n, int offset, int len);
77
78#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
79
80static inline int skb_route(struct sk_buff *skb, struct rtable **prt){
81    int err = 0;
82    struct flowi fl = {
83        .nl_u = {
84            .ip4_u = {
85                .daddr = skb->nh.iph->daddr,
86                .saddr = skb->nh.iph->saddr,
87                .tos   = skb->nh.iph->tos,
88            }
89        }
90    };
91   
92    if(skb->dev){
93        fl.oif = skb->dev->ifindex;
94    }
95    err = ip_route_output_key(prt, &fl);
96    return err;
97}
98
99#else
100
101static inline int skb_route(struct sk_buff *skb, struct rtable **prt){
102    int err = 0;
103    struct rt_key key = { };
104    key.dst = skb->nh.iph->daddr;
105    key.src = skb->nh.iph->saddr;
106    key.tos = skb->nh.iph->tos;
107    if(skb->dev){
108        key.oif = skb->dev->ifindex;
109    }
110    err = ip_route_output_key(prt, &key);
111    return err;
112}
113
114#endif
115
116#endif /* __KERNEL__ */
117
118/** Arp header struct with all the fields so we can access them. */
119struct arpheader
120{
121        unsigned short  ar_hrd;         /* format of hardware address   */
122        unsigned short  ar_pro;         /* format of protocol address   */
123        unsigned char   ar_hln;         /* length of hardware address   */
124        unsigned char   ar_pln;         /* length of protocol address   */
125        unsigned short  ar_op;          /* ARP opcode (command)         */
126
127#if 1
128         /*
129          *      Ethernet looks like this : This bit is variable sized however...
130          */
131        unsigned char           ar_sha[ETH_ALEN];       /* sender hardware address      */
132        unsigned char           ar_sip[4];              /* sender IP address            */
133        unsigned char           ar_tha[ETH_ALEN];       /* target hardware address      */
134        unsigned char           ar_tip[4];              /* target IP address            */
135#endif
136
137};
138
139#endif /* ! _VNET_SKB_UTIL_H_ */
Note: See TracBrowser for help on using the repository browser.