@@ -171,8 +171,10 @@ static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb)
171171void ip_cmsg_recv_offset (struct msghdr * msg , struct sock * sk ,
172172 struct sk_buff * skb , int tlen , int offset )
173173{
174- struct inet_sock * inet = inet_sk (sk );
175- unsigned int flags = inet -> cmsg_flags ;
174+ unsigned long flags = inet_cmsg_flags (inet_sk (sk ));
175+
176+ if (!flags )
177+ return ;
176178
177179 /* Ordered by supposed usage frequency */
178180 if (flags & IP_CMSG_PKTINFO ) {
@@ -568,7 +570,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
568570 if (ipv4_datagram_support_cmsg (sk , skb , serr -> ee .ee_origin )) {
569571 sin -> sin_family = AF_INET ;
570572 sin -> sin_addr .s_addr = ip_hdr (skb )-> saddr ;
571- if (inet_sk (sk )-> cmsg_flags )
573+ if (inet_cmsg_flags ( inet_sk (sk )) )
572574 ip_cmsg_recv (msg , skb );
573575 }
574576
@@ -635,7 +637,7 @@ EXPORT_SYMBOL(ip_sock_set_mtu_discover);
635637void ip_sock_set_pktinfo (struct sock * sk )
636638{
637639 lock_sock (sk );
638- inet_sk ( sk )-> cmsg_flags |= IP_CMSG_PKTINFO ;
640+ inet_set_bit ( PKTINFO , sk );
639641 release_sock (sk );
640642}
641643EXPORT_SYMBOL (ip_sock_set_pktinfo );
@@ -990,67 +992,43 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
990992 break ;
991993 }
992994 case IP_PKTINFO :
993- if (val )
994- inet -> cmsg_flags |= IP_CMSG_PKTINFO ;
995- else
996- inet -> cmsg_flags &= ~IP_CMSG_PKTINFO ;
995+ inet_assign_bit (PKTINFO , sk , val );
997996 break ;
998997 case IP_RECVTTL :
999- if (val )
1000- inet -> cmsg_flags |= IP_CMSG_TTL ;
1001- else
1002- inet -> cmsg_flags &= ~IP_CMSG_TTL ;
998+ inet_assign_bit (TTL , sk , val );
1003999 break ;
10041000 case IP_RECVTOS :
1005- if (val )
1006- inet -> cmsg_flags |= IP_CMSG_TOS ;
1007- else
1008- inet -> cmsg_flags &= ~IP_CMSG_TOS ;
1001+ inet_assign_bit (TOS , sk , val );
10091002 break ;
10101003 case IP_RECVOPTS :
1011- if (val )
1012- inet -> cmsg_flags |= IP_CMSG_RECVOPTS ;
1013- else
1014- inet -> cmsg_flags &= ~IP_CMSG_RECVOPTS ;
1004+ inet_assign_bit (RECVOPTS , sk , val );
10151005 break ;
10161006 case IP_RETOPTS :
1017- if (val )
1018- inet -> cmsg_flags |= IP_CMSG_RETOPTS ;
1019- else
1020- inet -> cmsg_flags &= ~IP_CMSG_RETOPTS ;
1007+ inet_assign_bit (RETOPTS , sk , val );
10211008 break ;
10221009 case IP_PASSSEC :
1023- if (val )
1024- inet -> cmsg_flags |= IP_CMSG_PASSSEC ;
1025- else
1026- inet -> cmsg_flags &= ~IP_CMSG_PASSSEC ;
1010+ inet_assign_bit (PASSSEC , sk , val );
10271011 break ;
10281012 case IP_RECVORIGDSTADDR :
1029- if (val )
1030- inet -> cmsg_flags |= IP_CMSG_ORIGDSTADDR ;
1031- else
1032- inet -> cmsg_flags &= ~IP_CMSG_ORIGDSTADDR ;
1013+ inet_assign_bit (ORIGDSTADDR , sk , val );
10331014 break ;
10341015 case IP_CHECKSUM :
10351016 if (val ) {
1036- if (!(inet -> cmsg_flags & IP_CMSG_CHECKSUM )) {
1017+ if (!(inet_test_bit ( CHECKSUM , sk ) )) {
10371018 inet_inc_convert_csum (sk );
1038- inet -> cmsg_flags |= IP_CMSG_CHECKSUM ;
1019+ inet_set_bit ( CHECKSUM , sk ) ;
10391020 }
10401021 } else {
1041- if (inet -> cmsg_flags & IP_CMSG_CHECKSUM ) {
1022+ if (inet_test_bit ( CHECKSUM , sk ) ) {
10421023 inet_dec_convert_csum (sk );
1043- inet -> cmsg_flags &= ~ IP_CMSG_CHECKSUM ;
1024+ inet_clear_bit ( CHECKSUM , sk ) ;
10441025 }
10451026 }
10461027 break ;
10471028 case IP_RECVFRAGSIZE :
10481029 if (sk -> sk_type != SOCK_RAW && sk -> sk_type != SOCK_DGRAM )
10491030 goto e_inval ;
1050- if (val )
1051- inet -> cmsg_flags |= IP_CMSG_RECVFRAGSIZE ;
1052- else
1053- inet -> cmsg_flags &= ~IP_CMSG_RECVFRAGSIZE ;
1031+ inet_assign_bit (RECVFRAGSIZE , sk , val );
10541032 break ;
10551033 case IP_TOS : /* This sets both TOS and Precedence */
10561034 __ip_sock_set_tos (sk , val );
@@ -1415,7 +1393,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
14151393void ipv4_pktinfo_prepare (const struct sock * sk , struct sk_buff * skb )
14161394{
14171395 struct in_pktinfo * pktinfo = PKTINFO_SKB_CB (skb );
1418- bool prepare = ( inet_sk ( sk ) -> cmsg_flags & IP_CMSG_PKTINFO ) ||
1396+ bool prepare = inet_test_bit ( PKTINFO , sk ) ||
14191397 ipv6_sk_rxinfo (sk );
14201398
14211399 if (prepare && skb_rtable (skb )) {
@@ -1601,31 +1579,31 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
16011579 return 0 ;
16021580 }
16031581 case IP_PKTINFO :
1604- val = ( inet -> cmsg_flags & IP_CMSG_PKTINFO ) != 0 ;
1582+ val = inet_test_bit ( PKTINFO , sk ) ;
16051583 break ;
16061584 case IP_RECVTTL :
1607- val = ( inet -> cmsg_flags & IP_CMSG_TTL ) != 0 ;
1585+ val = inet_test_bit ( TTL , sk ) ;
16081586 break ;
16091587 case IP_RECVTOS :
1610- val = ( inet -> cmsg_flags & IP_CMSG_TOS ) != 0 ;
1588+ val = inet_test_bit ( TOS , sk ) ;
16111589 break ;
16121590 case IP_RECVOPTS :
1613- val = ( inet -> cmsg_flags & IP_CMSG_RECVOPTS ) != 0 ;
1591+ val = inet_test_bit ( RECVOPTS , sk ) ;
16141592 break ;
16151593 case IP_RETOPTS :
1616- val = ( inet -> cmsg_flags & IP_CMSG_RETOPTS ) != 0 ;
1594+ val = inet_test_bit ( RETOPTS , sk ) ;
16171595 break ;
16181596 case IP_PASSSEC :
1619- val = ( inet -> cmsg_flags & IP_CMSG_PASSSEC ) != 0 ;
1597+ val = inet_test_bit ( PASSSEC , sk ) ;
16201598 break ;
16211599 case IP_RECVORIGDSTADDR :
1622- val = ( inet -> cmsg_flags & IP_CMSG_ORIGDSTADDR ) != 0 ;
1600+ val = inet_test_bit ( ORIGDSTADDR , sk ) ;
16231601 break ;
16241602 case IP_CHECKSUM :
1625- val = ( inet -> cmsg_flags & IP_CMSG_CHECKSUM ) != 0 ;
1603+ val = inet_test_bit ( CHECKSUM , sk ) ;
16261604 break ;
16271605 case IP_RECVFRAGSIZE :
1628- val = ( inet -> cmsg_flags & IP_CMSG_RECVFRAGSIZE ) != 0 ;
1606+ val = inet_test_bit ( RECVFRAGSIZE , sk ) ;
16291607 break ;
16301608 case IP_TOS :
16311609 val = inet -> tos ;
@@ -1737,19 +1715,19 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
17371715 msg .msg_controllen = len ;
17381716 msg .msg_flags = in_compat_syscall () ? MSG_CMSG_COMPAT : 0 ;
17391717
1740- if (inet -> cmsg_flags & IP_CMSG_PKTINFO ) {
1718+ if (inet_test_bit ( PKTINFO , sk ) ) {
17411719 struct in_pktinfo info ;
17421720
17431721 info .ipi_addr .s_addr = inet -> inet_rcv_saddr ;
17441722 info .ipi_spec_dst .s_addr = inet -> inet_rcv_saddr ;
17451723 info .ipi_ifindex = inet -> mc_index ;
17461724 put_cmsg (& msg , SOL_IP , IP_PKTINFO , sizeof (info ), & info );
17471725 }
1748- if (inet -> cmsg_flags & IP_CMSG_TTL ) {
1726+ if (inet_test_bit ( TTL , sk ) ) {
17491727 int hlim = inet -> mc_ttl ;
17501728 put_cmsg (& msg , SOL_IP , IP_TTL , sizeof (hlim ), & hlim );
17511729 }
1752- if (inet -> cmsg_flags & IP_CMSG_TOS ) {
1730+ if (inet_test_bit ( TOS , sk ) ) {
17531731 int tos = inet -> rcv_tos ;
17541732 put_cmsg (& msg , SOL_IP , IP_TOS , sizeof (tos ), & tos );
17551733 }
0 commit comments