sctp: define subscribe in sctp_sock as __u16
The member subscribe in sctp_sock is used to indicate to which of the events it is subscribed, more like a group of flags. So it's better to be defined as __u16 (2 bytpes), instead of struct sctp_event_subscribe (13 bytes). Note that sctp_event_subscribe is an UAPI struct, used on sockopt calls, and thus it will not be removed. This patch only changes the internal storage of the flags. Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
f2be6d710d
commit
2cc0eeb676
@@ -164,30 +164,39 @@ void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event,
|
||||
|
||||
__u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);
|
||||
|
||||
/* Is this event type enabled? */
|
||||
static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
|
||||
struct sctp_event_subscribe *mask)
|
||||
static inline void sctp_ulpevent_type_set(__u16 *subscribe,
|
||||
__u16 sn_type, __u8 on)
|
||||
{
|
||||
int offset = sn_type - SCTP_SN_TYPE_BASE;
|
||||
char *amask = (char *) mask;
|
||||
if (sn_type > SCTP_SN_TYPE_MAX)
|
||||
return;
|
||||
|
||||
if (offset >= sizeof(struct sctp_event_subscribe))
|
||||
return 0;
|
||||
return amask[offset];
|
||||
if (on)
|
||||
*subscribe |= (1 << (sn_type - SCTP_SN_TYPE_BASE));
|
||||
else
|
||||
*subscribe &= ~(1 << (sn_type - SCTP_SN_TYPE_BASE));
|
||||
}
|
||||
|
||||
/* Is this event type enabled? */
|
||||
static inline bool sctp_ulpevent_type_enabled(__u16 subscribe, __u16 sn_type)
|
||||
{
|
||||
if (sn_type > SCTP_SN_TYPE_MAX)
|
||||
return false;
|
||||
|
||||
return subscribe & (1 << (sn_type - SCTP_SN_TYPE_BASE));
|
||||
}
|
||||
|
||||
/* Given an event subscription, is this event enabled? */
|
||||
static inline int sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
|
||||
struct sctp_event_subscribe *mask)
|
||||
static inline bool sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
|
||||
__u16 subscribe)
|
||||
{
|
||||
__u16 sn_type;
|
||||
int enabled = 1;
|
||||
|
||||
if (sctp_ulpevent_is_notification(event)) {
|
||||
sn_type = sctp_ulpevent_get_notification_type(event);
|
||||
enabled = sctp_ulpevent_type_enabled(sn_type, mask);
|
||||
}
|
||||
return enabled;
|
||||
if (!sctp_ulpevent_is_notification(event))
|
||||
return true;
|
||||
|
||||
sn_type = sctp_ulpevent_get_notification_type(event);
|
||||
|
||||
return sctp_ulpevent_type_enabled(subscribe, sn_type);
|
||||
}
|
||||
|
||||
#endif /* __sctp_ulpevent_h__ */
|
||||
|
Reference in New Issue
Block a user