78 /* This is used to register socket interfaces for IP protocols. */ 79 struct inet_protosw { 80 struct list_head list; 81 82 /* These two fields form the lookup key. */ 83 unsigned short type; /* This is the 2nd argument to socket(2). */ 84 unsigned short protocol; /* This is the L4 protocol number. */ 85 86 struct proto *prot; 87 const struct proto_ops *ops; 88 89 unsigned char flags; /* See INET_PROTOSW_* below. */ 90 };
1030 1031 #define INETSW_ARRAY_LEN ARRAY_SIZE(inetsw_array) 1032 1033 void inet_register_protosw(struct inet_protosw *p) 1034 { 1035 struct list_head *lh; 1036 struct inet_protosw *answer; 1037 int protocol = p->protocol; 1038 struct list_head *last_perm; 1039 1040 spin_lock_bh(&inetsw_lock); 1041 1042 if (p->type >= SOCK_MAX) 1043 goto out_illegal; 1044 1045 /* If we are trying to override a permanent protocol, bail. */ 1046 last_perm = &inetsw[p->type]; 1047 list_for_each(lh, &inetsw[p->type]) { 1048 answer = list_entry(lh, struct inet_protosw, list); 1049 /* Check only the non-wild match. */ 1050 if ((INET_PROTOSW_PERMANENT & answer->flags) == 0) 1051 break; 1052 if (protocol == answer->protocol) 1053 goto out_permanent; 1054 last_perm = lh; 1055 } 1056 1057 /* Add the new entry after the last permanent entry if any, so that 1058 * the new entry does not override a permanent entry when matched with 1059 * a wild-card protocol. But it is allowed to override any existing 1060 * non-permanent entry. This means that when we remove this entry, the 1061 * system automatically returns to the old behavior. 1062 */ 1063 list_add_rcu(&p->list, last_perm); 1064 out: 1065 spin_unlock_bh(&inetsw_lock); 1066 1067 return; 1068 1069 out_permanent: 1070 pr_err("Attempt to override permanent protocol %d\n", protocol); 1071 gotoout; 1072 1073 out_illegal: 1074 pr_err("Ignoring attempt to register invalid socket type %d\n", 1075 p->type); 1076 gotoout; 1077 } 1078 EXPORT_SYMBOL(inet_register_protosw);