161 /*
162 * Global kstat instance counter. When a rule is created, its kstat instance
163 * number is assigned by ilb_kstat_instance and ilb_kstat_instance is
164 * incremented.
165 */
166 static uint_t ilb_kstat_instance = 0;
167
168 /*
169 * The ILB global kstat has name ILB_G_KS_NAME and class name ILB_G_KS_CNAME.
170 * A rule's kstat has ILB_RULE_KS_CNAME class name.
171 */
172 #define ILB_G_KS_NAME "global"
173 #define ILB_G_KS_CNAME "kstat"
174 #define ILB_RULE_KS_CNAME "rulestat"
175
176 static kstat_t *
177 ilb_kstat_g_init(netstackid_t stackid, ilb_stack_t *ilbs)
178 {
179 kstat_t *ksp;
180 ilb_g_kstat_t template = {
181 { "num_rules", KSTAT_DATA_UINT64, 0 },
182 { "ip_frag_in", KSTAT_DATA_UINT64, 0 },
183 { "ip_frag_dropped", KSTAT_DATA_UINT64, 0 }
184 };
185
186 ksp = kstat_create_netstack(ILB_KSTAT_MOD_NAME, 0, ILB_G_KS_NAME,
187 ILB_G_KS_CNAME, KSTAT_TYPE_NAMED, NUM_OF_FIELDS(ilb_g_kstat_t),
188 KSTAT_FLAG_VIRTUAL, stackid);
189 if (ksp == NULL)
190 return (NULL);
191 bcopy(&template, ilbs->ilbs_kstat, sizeof (template));
192 ksp->ks_data = ilbs->ilbs_kstat;
193 ksp->ks_private = (void *)(uintptr_t)stackid;
194
195 kstat_install(ksp);
196 return (ksp);
197 }
198
199 static void
200 ilb_kstat_g_fini(netstackid_t stackid, ilb_stack_t *ilbs)
201 {
202 if (ilbs->ilbs_ksp != NULL) {
203 ASSERT(stackid == (netstackid_t)(uintptr_t)
204 ilbs->ilbs_ksp->ks_private);
205 kstat_delete_netstack(ilbs->ilbs_ksp, stackid);
206 ilbs->ilbs_ksp = NULL;
207 }
208 }
209
210 static kstat_t *
211 ilb_rule_kstat_init(netstackid_t stackid, ilb_rule_t *rule)
212 {
213 kstat_t *ksp;
214 ilb_rule_kstat_t template = {
215 { "num_servers", KSTAT_DATA_UINT64, 0 },
216 { "bytes_not_processed", KSTAT_DATA_UINT64, 0 },
217 { "pkt_not_processed", KSTAT_DATA_UINT64, 0 },
218 { "bytes_dropped", KSTAT_DATA_UINT64, 0 },
219 { "pkt_dropped", KSTAT_DATA_UINT64, 0 },
220 { "nomem_bytes_dropped", KSTAT_DATA_UINT64, 0 },
221 { "nomem_pkt_dropped", KSTAT_DATA_UINT64, 0 },
222 { "noport_bytes_dropped", KSTAT_DATA_UINT64, 0 },
223 { "noport_pkt_dropped", KSTAT_DATA_UINT64, 0 },
224 { "icmp_echo_processed", KSTAT_DATA_UINT64, 0 },
225 { "icmp_dropped", KSTAT_DATA_UINT64, 0 },
226 { "icmp_too_big_processed", KSTAT_DATA_UINT64, 0 },
227 { "icmp_too_big_dropped", KSTAT_DATA_UINT64, 0 }
228 };
229
230 ksp = kstat_create_netstack(ILB_KSTAT_MOD_NAME, rule->ir_ks_instance,
231 rule->ir_name, ILB_RULE_KS_CNAME, KSTAT_TYPE_NAMED,
232 NUM_OF_FIELDS(ilb_rule_kstat_t), KSTAT_FLAG_VIRTUAL, stackid);
233 if (ksp == NULL)
234 return (NULL);
235
236 bcopy(&template, &rule->ir_kstat, sizeof (template));
237 ksp->ks_data = &rule->ir_kstat;
238 ksp->ks_private = (void *)(uintptr_t)stackid;
239
240 kstat_install(ksp);
241 return (ksp);
242 }
243
244 static kstat_t *
245 ilb_server_kstat_init(netstackid_t stackid, ilb_rule_t *rule,
246 ilb_server_t *server)
247 {
248 kstat_t *ksp;
249 ilb_server_kstat_t template = {
250 { "bytes_processed", KSTAT_DATA_UINT64, 0 },
251 { "pkt_processed", KSTAT_DATA_UINT64, 0 },
252 { "ip_address", KSTAT_DATA_STRING, 0 }
253 };
254 char cname_buf[KSTAT_STRLEN];
255
256 /* 7 is "-sstat" */
257 ASSERT(strlen(rule->ir_name) + 7 < KSTAT_STRLEN);
258 (void) sprintf(cname_buf, "%s-sstat", rule->ir_name);
259 ksp = kstat_create_netstack(ILB_KSTAT_MOD_NAME, rule->ir_ks_instance,
260 server->iser_name, cname_buf, KSTAT_TYPE_NAMED,
261 NUM_OF_FIELDS(ilb_server_kstat_t), KSTAT_FLAG_VIRTUAL, stackid);
262 if (ksp == NULL)
263 return (NULL);
264
265 bcopy(&template, &server->iser_kstat, sizeof (template));
266 ksp->ks_data = &server->iser_kstat;
267 ksp->ks_private = (void *)(uintptr_t)stackid;
268
269 kstat_named_setstr(&server->iser_kstat.ip_address,
270 server->iser_ip_addr);
271 /* We never change the IP address */
272 ksp->ks_data_size += strlen(server->iser_ip_addr) + 1;
|
161 /*
162 * Global kstat instance counter. When a rule is created, its kstat instance
163 * number is assigned by ilb_kstat_instance and ilb_kstat_instance is
164 * incremented.
165 */
166 static uint_t ilb_kstat_instance = 0;
167
168 /*
169 * The ILB global kstat has name ILB_G_KS_NAME and class name ILB_G_KS_CNAME.
170 * A rule's kstat has ILB_RULE_KS_CNAME class name.
171 */
172 #define ILB_G_KS_NAME "global"
173 #define ILB_G_KS_CNAME "kstat"
174 #define ILB_RULE_KS_CNAME "rulestat"
175
176 static kstat_t *
177 ilb_kstat_g_init(netstackid_t stackid, ilb_stack_t *ilbs)
178 {
179 kstat_t *ksp;
180 ilb_g_kstat_t template = {
181 { "num_rules", KSTAT_DATA_UINT64, {{0}} },
182 { "ip_frag_in", KSTAT_DATA_UINT64, {{0}} },
183 { "ip_frag_dropped", KSTAT_DATA_UINT64, {{0}} }
184 };
185
186 ksp = kstat_create_netstack(ILB_KSTAT_MOD_NAME, 0, ILB_G_KS_NAME,
187 ILB_G_KS_CNAME, KSTAT_TYPE_NAMED, NUM_OF_FIELDS(ilb_g_kstat_t),
188 KSTAT_FLAG_VIRTUAL, stackid);
189 if (ksp == NULL)
190 return (NULL);
191 bcopy(&template, ilbs->ilbs_kstat, sizeof (template));
192 ksp->ks_data = ilbs->ilbs_kstat;
193 ksp->ks_private = (void *)(uintptr_t)stackid;
194
195 kstat_install(ksp);
196 return (ksp);
197 }
198
199 static void
200 ilb_kstat_g_fini(netstackid_t stackid, ilb_stack_t *ilbs)
201 {
202 if (ilbs->ilbs_ksp != NULL) {
203 ASSERT(stackid == (netstackid_t)(uintptr_t)
204 ilbs->ilbs_ksp->ks_private);
205 kstat_delete_netstack(ilbs->ilbs_ksp, stackid);
206 ilbs->ilbs_ksp = NULL;
207 }
208 }
209
210 static kstat_t *
211 ilb_rule_kstat_init(netstackid_t stackid, ilb_rule_t *rule)
212 {
213 kstat_t *ksp;
214 ilb_rule_kstat_t template = {
215 { "num_servers", KSTAT_DATA_UINT64, {{0}} },
216 { "bytes_not_processed", KSTAT_DATA_UINT64, {{0}} },
217 { "pkt_not_processed", KSTAT_DATA_UINT64, {{0}} },
218 { "bytes_dropped", KSTAT_DATA_UINT64, {{0}} },
219 { "pkt_dropped", KSTAT_DATA_UINT64, {{0}} },
220 { "nomem_bytes_dropped", KSTAT_DATA_UINT64, {{0}} },
221 { "nomem_pkt_dropped", KSTAT_DATA_UINT64, {{0}} },
222 { "noport_bytes_dropped", KSTAT_DATA_UINT64, {{0}} },
223 { "noport_pkt_dropped", KSTAT_DATA_UINT64, {{0}} },
224 { "icmp_echo_processed", KSTAT_DATA_UINT64, {{0}} },
225 { "icmp_dropped", KSTAT_DATA_UINT64, {{0}} },
226 { "icmp_too_big_processed", KSTAT_DATA_UINT64, {{0}} },
227 { "icmp_too_big_dropped", KSTAT_DATA_UINT64, {{0}} }
228 };
229
230 ksp = kstat_create_netstack(ILB_KSTAT_MOD_NAME, rule->ir_ks_instance,
231 rule->ir_name, ILB_RULE_KS_CNAME, KSTAT_TYPE_NAMED,
232 NUM_OF_FIELDS(ilb_rule_kstat_t), KSTAT_FLAG_VIRTUAL, stackid);
233 if (ksp == NULL)
234 return (NULL);
235
236 bcopy(&template, &rule->ir_kstat, sizeof (template));
237 ksp->ks_data = &rule->ir_kstat;
238 ksp->ks_private = (void *)(uintptr_t)stackid;
239
240 kstat_install(ksp);
241 return (ksp);
242 }
243
244 static kstat_t *
245 ilb_server_kstat_init(netstackid_t stackid, ilb_rule_t *rule,
246 ilb_server_t *server)
247 {
248 kstat_t *ksp;
249 ilb_server_kstat_t template = {
250 { "bytes_processed", KSTAT_DATA_UINT64, {{0}} },
251 { "pkt_processed", KSTAT_DATA_UINT64, {{0}} },
252 { "ip_address", KSTAT_DATA_STRING, {{0}} }
253 };
254 char cname_buf[KSTAT_STRLEN];
255
256 /* 7 is "-sstat" */
257 ASSERT(strlen(rule->ir_name) + 7 < KSTAT_STRLEN);
258 (void) sprintf(cname_buf, "%s-sstat", rule->ir_name);
259 ksp = kstat_create_netstack(ILB_KSTAT_MOD_NAME, rule->ir_ks_instance,
260 server->iser_name, cname_buf, KSTAT_TYPE_NAMED,
261 NUM_OF_FIELDS(ilb_server_kstat_t), KSTAT_FLAG_VIRTUAL, stackid);
262 if (ksp == NULL)
263 return (NULL);
264
265 bcopy(&template, &server->iser_kstat, sizeof (template));
266 ksp->ks_data = &server->iser_kstat;
267 ksp->ks_private = (void *)(uintptr_t)stackid;
268
269 kstat_named_setstr(&server->iser_kstat.ip_address,
270 server->iser_ip_addr);
271 /* We never change the IP address */
272 ksp->ks_data_size += strlen(server->iser_ip_addr) + 1;
|