mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	ipv6: improve ipv6_find_hdr() to skip empty routing headers
This patch prepares ipv6_find_hdr() function so that it could be able to skip routing headers, where segements_left is 0. This is required to handle multiple routing header case correctly when changing IPv6 addresses. Signed-off-by: Ansis Atteka <aatteka@nicira.com> Signed-off-by: Jesse Gross <jesse@nicira.com>
This commit is contained in:
		
							parent
							
								
									f8f626754e
								
							
						
					
					
						commit
						9195bb8e38
					
				
					 2 changed files with 31 additions and 10 deletions
				
			
		| 
						 | 
					@ -633,6 +633,7 @@ extern bool			ipv6_ext_hdr(u8 nexthdr);
 | 
				
			||||||
enum {
 | 
					enum {
 | 
				
			||||||
	IP6_FH_F_FRAG		= (1 << 0),
 | 
						IP6_FH_F_FRAG		= (1 << 0),
 | 
				
			||||||
	IP6_FH_F_AUTH		= (1 << 1),
 | 
						IP6_FH_F_AUTH		= (1 << 1),
 | 
				
			||||||
 | 
						IP6_FH_F_SKIP_RH	= (1 << 2),
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* find specified header and get offset to it */
 | 
					/* find specified header and get offset to it */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,9 +132,11 @@ EXPORT_SYMBOL(ipv6_skip_exthdr);
 | 
				
			||||||
 * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
 | 
					 * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
 | 
				
			||||||
 * isn't NULL.
 | 
					 * isn't NULL.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * if flags is not NULL and it's a fragment, then the frag flag IP6_FH_F_FRAG
 | 
					 * if flags is not NULL and it's a fragment, then the frag flag
 | 
				
			||||||
 * will be set. If it's an AH header, the IP6_FH_F_AUTH flag is set and
 | 
					 * IP6_FH_F_FRAG will be set. If it's an AH header, the
 | 
				
			||||||
 * target < 0, then this function will stop at the AH header.
 | 
					 * IP6_FH_F_AUTH flag is set and target < 0, then this function will
 | 
				
			||||||
 | 
					 * stop at the AH header. If IP6_FH_F_SKIP_RH flag was passed, then this
 | 
				
			||||||
 | 
					 * function will skip all those routing headers, where segements_left was 0.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 | 
					int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 | 
				
			||||||
		  int target, unsigned short *fragoff, int *flags)
 | 
							  int target, unsigned short *fragoff, int *flags)
 | 
				
			||||||
| 
						 | 
					@ -142,6 +144,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 | 
				
			||||||
	unsigned int start = skb_network_offset(skb) + sizeof(struct ipv6hdr);
 | 
						unsigned int start = skb_network_offset(skb) + sizeof(struct ipv6hdr);
 | 
				
			||||||
	u8 nexthdr = ipv6_hdr(skb)->nexthdr;
 | 
						u8 nexthdr = ipv6_hdr(skb)->nexthdr;
 | 
				
			||||||
	unsigned int len;
 | 
						unsigned int len;
 | 
				
			||||||
 | 
						bool found;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (fragoff)
 | 
						if (fragoff)
 | 
				
			||||||
		*fragoff = 0;
 | 
							*fragoff = 0;
 | 
				
			||||||
| 
						 | 
					@ -159,9 +162,10 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	len = skb->len - start;
 | 
						len = skb->len - start;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (nexthdr != target) {
 | 
						do {
 | 
				
			||||||
		struct ipv6_opt_hdr _hdr, *hp;
 | 
							struct ipv6_opt_hdr _hdr, *hp;
 | 
				
			||||||
		unsigned int hdrlen;
 | 
							unsigned int hdrlen;
 | 
				
			||||||
 | 
							found = (nexthdr == target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) {
 | 
							if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) {
 | 
				
			||||||
			if (target < 0)
 | 
								if (target < 0)
 | 
				
			||||||
| 
						 | 
					@ -172,6 +176,20 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 | 
				
			||||||
		hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
 | 
							hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
 | 
				
			||||||
		if (hp == NULL)
 | 
							if (hp == NULL)
 | 
				
			||||||
			return -EBADMSG;
 | 
								return -EBADMSG;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (nexthdr == NEXTHDR_ROUTING) {
 | 
				
			||||||
 | 
								struct ipv6_rt_hdr _rh, *rh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								rh = skb_header_pointer(skb, start, sizeof(_rh),
 | 
				
			||||||
 | 
											&_rh);
 | 
				
			||||||
 | 
								if (rh == NULL)
 | 
				
			||||||
 | 
									return -EBADMSG;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (flags && (*flags & IP6_FH_F_SKIP_RH) &&
 | 
				
			||||||
 | 
								    rh->segments_left == 0)
 | 
				
			||||||
 | 
									found = false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (nexthdr == NEXTHDR_FRAGMENT) {
 | 
							if (nexthdr == NEXTHDR_FRAGMENT) {
 | 
				
			||||||
			unsigned short _frag_off;
 | 
								unsigned short _frag_off;
 | 
				
			||||||
			__be16 *fp;
 | 
								__be16 *fp;
 | 
				
			||||||
| 
						 | 
					@ -205,10 +223,12 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 | 
				
			||||||
		} else
 | 
							} else
 | 
				
			||||||
			hdrlen = ipv6_optlen(hp);
 | 
								hdrlen = ipv6_optlen(hp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!found) {
 | 
				
			||||||
			nexthdr = hp->nexthdr;
 | 
								nexthdr = hp->nexthdr;
 | 
				
			||||||
			len -= hdrlen;
 | 
								len -= hdrlen;
 | 
				
			||||||
			start += hdrlen;
 | 
								start += hdrlen;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						} while (!found);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	*offset = start;
 | 
						*offset = start;
 | 
				
			||||||
	return nexthdr;
 | 
						return nexthdr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue