@@ -74,6 +74,68 @@ static int zero_out_mutable_opts(struct ipv6_opt_hdr *opthdr)
7474 return 0 ;
7575}
7676
77+ #ifdef CONFIG_IPV6_MIP6
78+ /**
79+ * ipv6_rearrange_destopt - rearrange IPv6 destination options header
80+ * @iph: IPv6 header
81+ * @destopt: destionation options header
82+ */
83+ static void ipv6_rearrange_destopt (struct ipv6hdr * iph , struct ipv6_opt_hdr * destopt )
84+ {
85+ u8 * opt = (u8 * )destopt ;
86+ int len = ipv6_optlen (destopt );
87+ int off = 0 ;
88+ int optlen = 0 ;
89+
90+ off += 2 ;
91+ len -= 2 ;
92+
93+ while (len > 0 ) {
94+
95+ switch (opt [off ]) {
96+
97+ case IPV6_TLV_PAD0 :
98+ optlen = 1 ;
99+ break ;
100+ default :
101+ if (len < 2 )
102+ goto bad ;
103+ optlen = opt [off + 1 ]+ 2 ;
104+ if (len < optlen )
105+ goto bad ;
106+
107+ /* Rearrange the source address in @iph and the
108+ * addresses in home address option for final source.
109+ * See 11.3.2 of RFC 3775 for details.
110+ */
111+ if (opt [off ] == IPV6_TLV_HAO ) {
112+ struct in6_addr final_addr ;
113+ struct ipv6_destopt_hao * hao ;
114+
115+ hao = (struct ipv6_destopt_hao * )& opt [off ];
116+ if (hao -> length != sizeof (hao -> addr )) {
117+ if (net_ratelimit ())
118+ printk (KERN_WARNING "destopt hao: invalid header length: %u\n" , hao -> length );
119+ goto bad ;
120+ }
121+ ipv6_addr_copy (& final_addr , & hao -> addr );
122+ ipv6_addr_copy (& hao -> addr , & iph -> saddr );
123+ ipv6_addr_copy (& iph -> saddr , & final_addr );
124+ }
125+ break ;
126+ }
127+
128+ off += optlen ;
129+ len -= optlen ;
130+ }
131+ if (len == 0 )
132+ return ;
133+
134+ bad :
135+ return ;
136+ }
137+ #endif
138+
77139/**
78140 * ipv6_rearrange_rthdr - rearrange IPv6 routing header
79141 * @iph: IPv6 header
@@ -113,7 +175,11 @@ static void ipv6_rearrange_rthdr(struct ipv6hdr *iph, struct ipv6_rt_hdr *rthdr)
113175 ipv6_addr_copy (& iph -> daddr , & final_addr );
114176}
115177
178+ #ifdef CONFIG_IPV6_MIP6
179+ static int ipv6_clear_mutable_options (struct ipv6hdr * iph , int len , int dir )
180+ #else
116181static int ipv6_clear_mutable_options (struct ipv6hdr * iph , int len )
182+ #endif
117183{
118184 union {
119185 struct ipv6hdr * iph ;
@@ -128,6 +194,28 @@ static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len)
128194
129195 while (exthdr .raw < end ) {
130196 switch (nexthdr ) {
197+ #ifdef CONFIG_IPV6_MIP6
198+ case NEXTHDR_HOP :
199+ if (!zero_out_mutable_opts (exthdr .opth )) {
200+ LIMIT_NETDEBUG (
201+ KERN_WARNING "overrun %sopts\n" ,
202+ nexthdr == NEXTHDR_HOP ?
203+ "hop" : "dest" );
204+ return - EINVAL ;
205+ }
206+ break ;
207+ case NEXTHDR_DEST :
208+ if (dir == XFRM_POLICY_OUT )
209+ ipv6_rearrange_destopt (iph , exthdr .opth );
210+ if (!zero_out_mutable_opts (exthdr .opth )) {
211+ LIMIT_NETDEBUG (
212+ KERN_WARNING "overrun %sopts\n" ,
213+ nexthdr == NEXTHDR_HOP ?
214+ "hop" : "dest" );
215+ return - EINVAL ;
216+ }
217+ break ;
218+ #else
131219 case NEXTHDR_HOP :
132220 case NEXTHDR_DEST :
133221 if (!zero_out_mutable_opts (exthdr .opth )) {
@@ -138,6 +226,7 @@ static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len)
138226 return - EINVAL ;
139227 }
140228 break ;
229+ #endif
141230
142231 case NEXTHDR_ROUTING :
143232 ipv6_rearrange_rthdr (iph , exthdr .rth );
@@ -164,6 +253,9 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
164253 u8 nexthdr ;
165254 char tmp_base [8 ];
166255 struct {
256+ #ifdef CONFIG_IPV6_MIP6
257+ struct in6_addr saddr ;
258+ #endif
167259 struct in6_addr daddr ;
168260 char hdrs [0 ];
169261 } * tmp_ext ;
@@ -188,10 +280,18 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
188280 err = - ENOMEM ;
189281 goto error ;
190282 }
283+ #ifdef CONFIG_IPV6_MIP6
284+ memcpy (tmp_ext , & top_iph -> saddr , extlen );
285+ err = ipv6_clear_mutable_options (top_iph ,
286+ extlen - sizeof (* tmp_ext ) +
287+ sizeof (* top_iph ),
288+ XFRM_POLICY_OUT );
289+ #else
191290 memcpy (tmp_ext , & top_iph -> daddr , extlen );
192291 err = ipv6_clear_mutable_options (top_iph ,
193292 extlen - sizeof (* tmp_ext ) +
194293 sizeof (* top_iph ));
294+ #endif
195295 if (err )
196296 goto error_free_iph ;
197297 }
@@ -222,7 +322,11 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
222322
223323 memcpy (top_iph , tmp_base , sizeof (tmp_base ));
224324 if (tmp_ext ) {
325+ #ifdef CONFIG_IPV6_MIP6
326+ memcpy (& top_iph -> saddr , tmp_ext , extlen );
327+ #else
225328 memcpy (& top_iph -> daddr , tmp_ext , extlen );
329+ #endif
226330error_free_iph :
227331 kfree (tmp_ext );
228332 }
@@ -282,8 +386,13 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
282386 if (!tmp_hdr )
283387 goto out ;
284388 memcpy (tmp_hdr , skb -> nh .raw , hdr_len );
389+ #ifdef CONFIG_IPV6_MIP6
390+ if (ipv6_clear_mutable_options (skb -> nh .ipv6h , hdr_len , XFRM_POLICY_IN ))
391+ goto free_out ;
392+ #else
285393 if (ipv6_clear_mutable_options (skb -> nh .ipv6h , hdr_len ))
286394 goto free_out ;
395+ #endif
287396 skb -> nh .ipv6h -> priority = 0 ;
288397 skb -> nh .ipv6h -> flow_lbl [0 ] = 0 ;
289398 skb -> nh .ipv6h -> flow_lbl [1 ] = 0 ;
0 commit comments