Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/sockfs/sockfilter_impl.h
+++ new/usr/src/uts/common/fs/sockfs/sockfilter_impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 #ifndef _SOCKFS_SOCKFILTER_H
26 26 #define _SOCKFS_SOCKFILTER_H
27 27
28 28 #include <sys/kstat.h>
29 29 #include <sys/list.h>
30 30 #include <sys/mutex.h>
31 31 #include <sys/socket.h>
32 32 #include <sys/socketvar.h>
33 33 #include <sys/sockfilter.h>
34 34
35 35 #ifdef __cplusplus
36 36 extern "C" {
37 37 #endif
38 38
39 39 struct sonode;
40 40 struct sockparams;
41 41
42 42 typedef struct sof_module sof_module_t;
43 43 typedef struct sof_entry_kstat sof_entry_kstat_t;
44 44 typedef struct sof_entry sof_entry_t;
45 45 typedef struct sof_instance sof_instance_t;
46 46 typedef struct sof_kstat sof_kstat_t;
47 47
48 48 #define SOF_MAXNAMELEN FILNAME_MAX
49 49 #define SOF_MAXSOCKTUPLECNT 32
50 50 #define SOF_MODPATH SOCKMOD_PATH
51 51
52 52 struct sof_module {
53 53 char *sofm_name;
54 54 sof_ops_t sofm_ops;
55 55 uint_t sofm_refcnt;
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
56 56 list_node_t sofm_node;
57 57 };
58 58
59 59 struct sof_kstat {
60 60 kstat_named_t sofks_defer_closed;
61 61 kstat_named_t sofks_defer_close_backlog;
62 62 kstat_named_t sofks_defer_close_failed_backlog_too_big;
63 63 };
64 64
65 65 #define SOF_GLOBAL_STAT_BUMP(s) \
66 - atomic_add_64(&sof_stat.sofks_##s.value.ui64, 1)
66 + atomic_inc_64(&sof_stat.sofks_##s.value.ui64)
67 67
68 68 /*
69 69 * Per filter statistics.
70 70 */
71 71 struct sof_entry_kstat {
72 72 kstat_named_t sofek_nactive; /* # of consumers */
73 73 kstat_named_t sofek_tot_active_attach;
74 74 kstat_named_t sofek_tot_passive_attach;
75 75 kstat_named_t sofek_ndeferred; /* # of deferred conns */
76 76 kstat_named_t sofek_attach_failures;
77 77 };
78 78
79 79 /*
80 80 * Socket filter entry - one for each configured filter (added and
81 81 * removed by soconfig(1M)).
82 82 *
83 83 * sofe_flags, sofe_refcnt and sofe_mod are protected by sofe_lock, and all
84 84 * other fields are write once.
85 85 */
86 86 struct sof_entry {
87 87 char sofe_name[SOF_MAXNAMELEN]; /* filter name */
88 88 char sofe_modname[MODMAXNAMELEN]; /* filter module */
89 89 sof_hint_t sofe_hint; /* order hint */
90 90 char *sofe_hintarg; /* hint argument */
91 91 list_node_t sofe_node; /* global list node */
92 92 uint_t sofe_socktuple_cnt; /* # of socket tuples */
93 93 sof_socktuple_t *sofe_socktuple; /* socket tuple list */
94 94
95 95 sof_entry_kstat_t sofe_kstat; /* filter stats */
96 96 kstat_t *sofe_ksp;
97 97
98 98 kmutex_t sofe_lock;
99 99 char sofe_flags; /* SOFEF_* flags */
100 100 uint_t sofe_refcnt; /* # of instances */
101 101 sof_module_t *sofe_mod; /* filter module */
102 102 };
103 103
104 104 /* Filter entry flags */
105 105 #define SOFEF_AUTO 0x1 /* automatic filter */
106 106 #define SOFEF_PROG 0x2 /* programmatic filter */
107 107 #define SOFEF_CONDEMED 0x4 /* removed by soconfig(1M) */
108 108
109 109 /*
110 110 * Socket filter instance - one for each socket using a sof_entry_t
111 111 */
112 112 struct sof_instance {
113 113 sof_ops_t *sofi_ops; /* filter ops */
114 114 void *sofi_cookie; /* filter cookie (from attach) */
115 115 char sofi_flags; /* instance flags (SOFIF_*) */
116 116 sof_instance_t *sofi_prev; /* up the stack */
117 117 sof_instance_t *sofi_next; /* down the stack */
118 118 struct sonode *sofi_sonode; /* socket instance is attached to */
119 119 sof_entry_t *sofi_filter; /* filter this is an instance of */
120 120 };
121 121
122 122 /* Filter instance flags */
123 123 #define SOFIF_BYPASS 0x1 /* filter does not want any callbacks */
124 124 #define SOFIF_DEFER 0x2 /* defer notification of socket */
125 125 #define SOFIF_RCV_FLOWCTRL 0x4 /* flow control recv path */
126 126 #define SOFIF_SND_FLOWCTRL 0x8 /* flow control send path */
127 127
128 128 #define SOF_STAT_ADD(i, s, v) \
129 129 atomic_add_64(&(i)->sofi_filter->sofe_kstat.sofek_##s.value.ui64, (v))
130 130
131 131 extern void sof_init(void);
132 132
133 133 extern void sof_entry_free(sof_entry_t *);
134 134 extern int sof_entry_add(sof_entry_t *);
135 135 extern sof_entry_t *sof_entry_remove_by_name(const char *);
136 136 extern int sof_entry_proc_sockparams(sof_entry_t *, struct sockparams *);
137 137
138 138 extern int sof_sockparams_init(struct sockparams *);
139 139 extern void sof_sockparams_fini(struct sockparams *);
140 140
141 141 extern int sof_sonode_autoattach_filters(struct sonode *, cred_t *);
142 142 extern int sof_sonode_inherit_filters(struct sonode *, struct sonode *);
143 143 extern void sof_sonode_closing(struct sonode *);
144 144 extern void sof_sonode_cleanup(struct sonode *);
145 145 extern void sof_sonode_notify_filters(struct sonode *, sof_event_t,
146 146 uintptr_t);
147 147 extern boolean_t sof_sonode_drop_deferred(struct sonode *);
148 148
149 149 extern int sof_setsockopt(struct sonode *, int, const void *, socklen_t,
150 150 struct cred *);
151 151 extern int sof_getsockopt(struct sonode *, int, void *, socklen_t *,
152 152 struct cred *);
153 153
154 154 extern int sof_rval2errno(sof_rval_t);
155 155
156 156 #define SOF_INTERESTED(inst, op) \
157 157 (!((inst)->sofi_flags & SOFIF_BYPASS) && \
158 158 (inst)->sofi_ops->sofop_##op != NULL)
159 159
160 160 /*
161 161 * SOF_FILTER_OP traverses the filter stack for sonode `so' top-down,
162 162 * calling `op' for each filter with the supplied `args'. A non-negative
163 163 * return value indicates that a filter action was taken.
164 164 */
165 165 #define __SOF_FILTER_OP(so, op, cr, ...) \
166 166 sof_instance_t *__inst; \
167 167 sof_rval_t __rval; \
168 168 \
169 169 for (__inst = (so)->so_filter_top; __inst != NULL; \
170 170 __inst = __inst->sofi_next) { \
171 171 if (!SOF_INTERESTED(__inst, op)) \
172 172 continue; \
173 173 __rval = (__inst->sofi_ops->sofop_##op)((sof_handle_t)__inst,\
174 174 __inst->sofi_cookie, __VA_ARGS__, cr); \
175 175 DTRACE_PROBE2(filter__action, (sof_instance_t), __inst,\
176 176 (sof_rval_t), __rval); \
177 177 if (__rval != SOF_RVAL_CONTINUE) \
178 178 return (sof_rval2errno(__rval)); \
179 179 } \
180 180 return (-1);
181 181
182 182 extern mblk_t *sof_filter_data_out_from(struct sonode *so,
183 183 sof_instance_t *, mblk_t *, struct nmsghdr *, cred_t *, int *);
184 184 extern mblk_t *sof_filter_data_in_proc(struct sonode *so,
185 185 mblk_t *, mblk_t **);
186 186 extern int sof_filter_bind(struct sonode *, struct sockaddr *,
187 187 socklen_t *, cred_t *);
188 188 extern int sof_filter_listen(struct sonode *, int *, cred_t *);
189 189 extern int sof_filter_connect(struct sonode *, struct sockaddr *,
190 190 socklen_t *, cred_t *);
191 191 extern int sof_filter_accept(struct sonode *, cred_t *);
192 192 extern int sof_filter_shutdown(struct sonode *, int *, cred_t *);
193 193 extern int sof_filter_getsockname(struct sonode *, struct sockaddr *,
194 194 socklen_t *, cred_t *);
195 195 extern int sof_filter_getpeername(struct sonode *, struct sockaddr *,
196 196 socklen_t *, cred_t *);
197 197 extern int sof_filter_setsockopt(struct sonode *, int, int, void *,
198 198 socklen_t *, cred_t *);
199 199 extern int sof_filter_getsockopt(struct sonode *, int, int, void *,
200 200 socklen_t *, cred_t *);
201 201 extern int sof_filter_ioctl(struct sonode *, int, intptr_t, int,
202 202 int32_t *, cred_t *);
203 203
204 204 #define SOF_FILTER_DATA_OUT(so, mp, msg, cr, errp) \
205 205 sof_filter_data_out_from(so, (so)->so_filter_top, mp, msg, cr, errp)
206 206 #define SOF_FILTER_DATA_OUT_FROM(so, inst, mp, msg, cr, errp) \
207 207 sof_filter_data_out_from(so, inst, mp, msg, cr, errp)
208 208
209 209 #ifdef __cplusplus
210 210 }
211 211 #endif
212 212
213 213 #endif /* _SOCKFS_SOCKFILTER_H */
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX