Deleted Added
sdiff udiff text old ( 123922 ) new ( 123992 )
full compact
1/* $NetBSD: ip_gre.c,v 1.21 2002/08/14 00:23:30 itojun Exp $ */
2/* $FreeBSD: head/sys/netinet/ip_gre.c 123922 2003-12-28 03:56:00Z sam $ */
3
4/*
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Heiko W.Rupp <hwr@pilhuhn.de>
10 *

--- 89 unchanged lines hidden (view full) ---

100 * IPPROTO_GRE and a local destination address).
101 * This really is simple
102 */
103void
104#if __STDC__
105gre_input(struct mbuf *m, ...)
106#else
107gre_input(m, va_alist)
108 struct mbuf *m;
109 va_dcl
110#endif
111{
112 int off, ret, proto;
113 va_list ap;
114
115 va_start(ap, m);
116 off = va_arg(ap, int);
117 va_end(ap);

--- 12 unchanged lines hidden (view full) ---

130/*
131 * decapsulate.
132 * Does the real work and is called from gre_input() (above)
133 * returns 0 if packet is not yet processed
134 * and 1 if it needs no further processing
135 * proto is the protocol number of the "calling" foo_input()
136 * routine.
137 */
138
139static int
140gre_input2(struct mbuf *m ,int hlen, u_char proto)
141{
142 struct greip *gip = mtod(m, struct greip *);
143 int isr;
144 struct gre_softc *sc;
145 u_short flags;
146
147 if ((sc = gre_lookup(m, proto)) == NULL) {
148 /* No matching tunnel or tunnel is down. */
149 return (0);
150 }
151
152 sc->sc_if.if_ipackets++;
153 sc->sc_if.if_ibytes += m->m_pkthdr.len;
154
155 switch (proto) {
156 case IPPROTO_GRE:
157 hlen += sizeof (struct gre_h);
158
159 /* process GRE flags as packet can be of variable len */
160 flags = ntohs(gip->gi_flags);
161
162 /* Checksum & Offset are present */
163 if ((flags & GRE_CP) | (flags & GRE_RP))
164 hlen += 4;
165 /* We don't support routing fields (variable length) */
166 if (flags & GRE_RP)
167 return(0);
168 if (flags & GRE_KP)
169 hlen += 4;
170 if (flags & GRE_SP)
171 hlen +=4;
172
173 switch (ntohs(gip->gi_ptype)) { /* ethertypes */
174 case ETHERTYPE_IP: /* shouldn't need a schednetisr(), as */
175 case WCCP_PROTOCOL_TYPE: /* we are in ip_input */
176 isr = NETISR_IP;
177 break;
178#ifdef NETATALK
179 case ETHERTYPE_ATALK:
180 isr = NETISR_ATALK1;
181 break;
182#endif
183 case ETHERTYPE_IPV6:
184 /* FALLTHROUGH */
185 default: /* others not yet supported */
186 return(0);
187 }
188 break;
189 default:
190 /* others not yet supported */
191 return(0);
192 }
193
194 m->m_data += hlen;
195 m->m_len -= hlen;
196 m->m_pkthdr.len -= hlen;
197
198 if (sc->sc_if.if_bpf) {
199 u_int32_t af = AF_INET;
200 bpf_mtap2(sc->sc_if.if_bpf, &af, sizeof(af), m);
201 }
202
203 m->m_pkthdr.rcvif = &sc->sc_if;
204
205 netisr_dispatch(isr, m);
206
207 return(1); /* packet is done, no further processing needed */
208}
209
210/*
211 * input routine for IPPRPOTO_MOBILE
212 * This is a little bit diffrent from the other modes, as the
213 * encapsulating header was not prepended, but instead inserted
214 * between IP header and payload
215 */
216
217void
218#if __STDC__
219gre_mobile_input(struct mbuf *m, ...)
220#else
221gre_mobile_input(m, va_alist)
222 struct mbuf *m;
223 va_dcl
224#endif
225{
226 struct ip *ip = mtod(m, struct ip *);
227 struct mobip_h *mip = mtod(m, struct mobip_h *);
228 struct gre_softc *sc;
229 int hlen;
230 va_list ap;
231 u_char osrc = 0;
232 int msiz;
233
234 va_start(ap,m);
235 hlen = va_arg(ap, int);
236 va_end(ap);
237
238 if ((sc = gre_lookup(m, IPPROTO_MOBILE)) == NULL) {
239 /* No matching tunnel or tunnel is down. */
240 m_freem(m);
241 return;
242 }
243
244 sc->sc_if.if_ipackets++;
245 sc->sc_if.if_ibytes += m->m_pkthdr.len;
246
247 if(ntohs(mip->mh.proto) & MOB_H_SBIT) {
248 osrc = 1;
249 msiz = MOB_H_SIZ_L;
250 mip->mi.ip_src.s_addr = mip->mh.osrc;
251 } else {
252 msiz = MOB_H_SIZ_S;
253 }
254 mip->mi.ip_dst.s_addr = mip->mh.odst;
255 mip->mi.ip_p = (ntohs(mip->mh.proto) >> 8);
256
257 if (gre_in_cksum((u_short*)&mip->mh,msiz) != 0) {
258 m_freem(m);
259 return;
260 }
261
262 bcopy((caddr_t)(ip) + (ip->ip_hl << 2) + msiz, (caddr_t)(ip) +
263 (ip->ip_hl << 2), m->m_len - msiz - (ip->ip_hl << 2));
264 m->m_len -= msiz;
265 m->m_pkthdr.len -= msiz;

--- 45 unchanged lines hidden ---