Skip to content

Commit 46bd64c

Browse files
Dave Barachflorincoras
authored andcommitted
mactime: upstream bugfixes
null terminate device name re-adding existing device clears old ranges and replaces name deleting a device frees device_name to fix leak return "No device data" when the device pool is empty Type: fix Change-Id: I832bb90579c54f1d3bd5c057293b6c5851ffccbb Signed-off-by: Dave Barach <dave@barachs.net>
1 parent 7bfb74b commit 46bd64c

5 files changed

Lines changed: 25 additions & 46 deletions

File tree

‎src/plugins/mactime/mactime.api‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ autoreply define mactime_add_del_range
8383
bool drop; /**< drop flag */
8484
bool allow; /**< allow flag */
8585
u8 allow_quota; /**< allow subject to quota */
86-
bool no_udp_10001; /**< drop udp to port 10001 */
86+
bool no_udp_10001; /**< deprecated, ignored */
8787
u64 data_quota; /**< max bytes this device */
8888
vl_api_mac_address_t mac_address; /**< src mac address */
8989
string device_name[64]; /**< device name */

‎src/plugins/mactime/mactime.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ static void vl_api_mactime_add_del_range_t_handler
284284
if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
285285
found = 0;
286286

287+
if (mp->no_udp_10001)
288+
clib_warning ("no_udp_10001 is deprecated and ignored");
289+
290+
/* Null Terminate the device name, for sure... */
291+
mp->device_name[ARRAY_LEN (mp->device_name) - 1] = 0;
292+
287293
/* Add an entry? */
288294
if (mp->is_add)
289295
{
@@ -298,7 +304,6 @@ static void vl_api_mactime_add_del_range_t_handler
298304
vlib_validate_combined_counter (&mm->drop_counters,
299305
dp - mm->devices);
300306
vlib_zero_combined_counter (&mm->drop_counters, dp - mm->devices);
301-
mp->device_name[ARRAY_LEN (mp->device_name) - 1] = 0;
302307
dp->device_name = format (0, "%s%c", mp->device_name, 0);
303308
memcpy (dp->mac_address, mp->mac_address, sizeof (mp->mac_address));
304309
for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
@@ -327,18 +332,21 @@ static void vl_api_mactime_add_del_range_t_handler
327332
if (mp->allow)
328333
dp->flags = MACTIME_DEVICE_FLAG_STATIC_ALLOW;
329334
}
330-
if (mp->no_udp_10001)
331-
dp->flags |= MACTIME_DEVICE_FLAG_DROP_UDP_10001;
332335

333336
dp->data_quota = data_quota;
334337

335338
/* Add the hash table entry */
336339
kv.value = dp - mm->devices;
337340
clib_bihash_add_del_8_8 (lut, &kv, 1 /* is_add */ );
338341
}
339-
else /* add more ranges, flags, etc. */
342+
else
340343
{
341344
dp = pool_elt_at_index (mm->devices, kv.value);
345+
/* Reset the range vector */
346+
vec_reset_length (dp->ranges);
347+
/* And the device name */
348+
vec_free (dp->device_name);
349+
dp->device_name = format (0, "%s%c", mp->device_name, 0);
342350

343351
for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
344352
{
@@ -366,8 +374,6 @@ static void vl_api_mactime_add_del_range_t_handler
366374
if (mp->allow)
367375
dp->flags = MACTIME_DEVICE_FLAG_STATIC_ALLOW;
368376
}
369-
if (mp->no_udp_10001)
370-
dp->flags |= MACTIME_DEVICE_FLAG_DROP_UDP_10001;
371377

372378
dp->data_quota = data_quota;
373379
}
@@ -386,6 +392,7 @@ static void vl_api_mactime_add_del_range_t_handler
386392
/* Remove it from the lookup table */
387393
clib_bihash_add_del_8_8 (lut, &kv, 0 /* is_add */ );
388394
vec_free (dp->ranges);
395+
vec_free (dp->device_name);
389396
pool_put (mm->devices, dp);
390397
}
391398

@@ -532,6 +539,9 @@ show_mactime_command_fn (vlib_main_t * vm,
532539
(0,
533540
"Feature not initialized, suggest 'help mactime enable-disable'...");
534541

542+
if (pool_elts (mm->devices) == 0)
543+
return clib_error_return (0, "No device data...");
544+
535545
vec_reset_length (mm->arp_cache_copy);
536546
/* Walk all ip4 neighbours on all interfaces */
537547
ip_neighbor_walk (AF_IP4, ~0, mactime_ip_neighbor_copy, mm);

‎src/plugins/mactime/mactime_device.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ typedef struct
2929
#define MACTIME_DEVICE_FLAG_DYNAMIC_DROP (1<<2)
3030
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW (1<<3)
3131
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA (1<<4)
32-
#define MACTIME_DEVICE_FLAG_DROP_UDP_10001 (1<<5)
3332

3433
#endif /* included_mactime_device_h */

‎src/plugins/mactime/mactime_test.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ api_mactime_add_del_range (vat_main_t * vam)
310310
u8 allow = 0;
311311
u8 allow_quota = 0;
312312
u8 drop = 0;
313-
u8 no_udp_10001 = 0;
314313
u64 data_quota = 0;
315314
int ret;
316315
int ii;
@@ -336,8 +335,6 @@ api_mactime_add_del_range (vat_main_t * vam)
336335
allow = 1;
337336
else if (unformat (i, "drop-static"))
338337
drop = 1;
339-
else if (unformat (i, "no-udp-10001"))
340-
no_udp_10001 = 1;
341338
else if (unformat (i, "mac %U", my_unformat_mac_address, mac_address))
342339
mac_set = 1;
343340
else if (unformat (i, "del"))
@@ -390,7 +387,6 @@ api_mactime_add_del_range (vat_main_t * vam)
390387
mp->drop = drop;
391388
mp->allow = allow;
392389
mp->allow_quota = allow_quota;
393-
mp->no_udp_10001 = no_udp_10001;
394390
mp->data_quota = clib_host_to_net_u64 (data_quota);
395391
memcpy (mp->mac_address, mac_address, sizeof (mp->mac_address));
396392
memcpy (mp->device_name, device_name, vec_len (device_name));

‎src/plugins/mactime/node.c‎

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ typedef struct
2121
vlib_node_registration_t mactime_node;
2222
vlib_node_registration_t mactime_tx_node;
2323

24-
#define foreach_mactime_error \
25-
_(OK, "Permitted packets") \
26-
_(STATIC_DROP, "Static drop packets") \
27-
_(RANGE_DROP, "Range drop packets") \
28-
_(QUOTA_DROP, "Data quota drop packets") \
29-
_(DROP_10001, "Dropped UDP DST-port 10001")
24+
#define foreach_mactime_error \
25+
_ (OK, "Permitted packets") \
26+
_ (STATIC_DROP, "Static drop packets") \
27+
_ (RANGE_DROP, "Range drop packets") \
28+
_ (QUOTA_DROP, "Data quota drop packets")
3029

3130
typedef enum
3231
{
@@ -193,34 +192,9 @@ mactime_node_inline (vlib_main_t * vm,
193192
}
194193
else /* note next0 set to allow */
195194
{
196-
/*
197-
* Special-case mini-ACL for a certain species of
198-
* home security DVR which likes to "call home."
199-
*/
200-
if (PREDICT_FALSE
201-
(dp->flags & MACTIME_DEVICE_FLAG_DROP_UDP_10001))
202-
{
203-
ip4_header_t *ip = (void *) (((u8 *) en0) + 14);
204-
udp_header_t *udp = (udp_header_t *) (ip + 1);
205-
if (ip->protocol != IP_PROTOCOL_UDP)
206-
goto pass;
207-
if (clib_net_to_host_u16 (udp->dst_port) == 10001 ||
208-
clib_net_to_host_u16 (udp->dst_port) == 9603)
209-
{
210-
next0 = MACTIME_NEXT_DROP;
211-
b0->error = node->errors[MACTIME_ERROR_DROP_10001];
212-
}
213-
else
214-
goto pass;
215-
}
216-
else
217-
{
218-
pass:
219-
vlib_increment_combined_counter
220-
(&mm->allow_counters, thread_index, dp - mm->devices,
221-
1, len0);
222-
packets_ok++;
223-
}
195+
vlib_increment_combined_counter (&mm->allow_counters, thread_index,
196+
dp - mm->devices, 1, len0);
197+
packets_ok++;
224198
}
225199
goto trace0;
226200
}

0 commit comments

Comments
 (0)