2000-04-17 07:53:29 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- Set/Community-list Operations
|
|
|
|
*
|
|
|
|
* (c) 2000 Martin Mares <mj@ucw.cz>
|
|
|
|
* (c) 2000 Pavel Machek <pavel@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/route.h"
|
2000-04-17 10:18:55 +00:00
|
|
|
#include "nest/attrs.h"
|
2000-04-17 07:53:29 +00:00
|
|
|
#include "lib/resource.h"
|
2000-04-17 10:18:55 +00:00
|
|
|
#include "lib/string.h"
|
|
|
|
|
|
|
|
void
|
2008-11-08 22:33:22 +00:00
|
|
|
int_set_format(struct adata *set, int way, byte *buf, unsigned int size)
|
2000-04-17 10:18:55 +00:00
|
|
|
{
|
|
|
|
u32 *z = (u32 *) set->data;
|
|
|
|
int l = set->length / 4;
|
|
|
|
int sp = 1;
|
|
|
|
byte *end = buf + size - 16;
|
|
|
|
|
|
|
|
while (l--)
|
|
|
|
{
|
2000-04-17 11:49:41 +00:00
|
|
|
if (!sp)
|
|
|
|
*buf++ = ' ';
|
2000-04-17 10:18:55 +00:00
|
|
|
if (buf > end)
|
|
|
|
{
|
|
|
|
strcpy(buf, "...");
|
|
|
|
return;
|
|
|
|
}
|
2008-11-08 22:33:22 +00:00
|
|
|
|
|
|
|
if (way)
|
|
|
|
buf += bsprintf(buf, "(%d,%d)", *z >> 16, *z & 0xffff);
|
|
|
|
else
|
|
|
|
buf += bsprintf(buf, "%d.%d.%d.%d",
|
|
|
|
(*z >> 24) & 0xff, (*z >> 16) & 0xff,
|
|
|
|
(*z >> 8) & 0xff, *z & 0xff);
|
|
|
|
|
2000-04-17 10:18:55 +00:00
|
|
|
z++;
|
2000-04-17 11:49:41 +00:00
|
|
|
sp = 0;
|
2000-04-17 10:18:55 +00:00
|
|
|
}
|
|
|
|
*buf = 0;
|
|
|
|
}
|
2000-04-17 11:34:38 +00:00
|
|
|
|
|
|
|
struct adata *
|
|
|
|
int_set_add(struct linpool *pool, struct adata *list, u32 val)
|
|
|
|
{
|
2008-10-26 21:45:09 +00:00
|
|
|
int len = list ? list->length : 0;
|
|
|
|
struct adata *res = lp_alloc(pool, len + sizeof(struct adata) + 4);
|
|
|
|
res->length = len + 4;
|
2000-04-17 11:34:38 +00:00
|
|
|
* (u32 *) res->data = val;
|
2008-10-26 21:45:09 +00:00
|
|
|
if (list)
|
|
|
|
memcpy((char *) res->data + 4, list->data, list->length);
|
2000-04-17 11:34:38 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
int_set_contains(struct adata *list, u32 val)
|
|
|
|
{
|
2000-04-17 11:49:41 +00:00
|
|
|
u32 *l = (u32 *) list->data;
|
|
|
|
unsigned int i;
|
2000-04-17 11:34:38 +00:00
|
|
|
for (i=0; i<list->length/4; i++)
|
|
|
|
if (*l++ == val)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct adata *
|
|
|
|
int_set_del(struct linpool *pool, struct adata *list, u32 val)
|
|
|
|
{
|
|
|
|
struct adata *res;
|
|
|
|
u32 *l, *k;
|
2000-04-17 11:49:41 +00:00
|
|
|
unsigned int i;
|
2000-04-17 11:34:38 +00:00
|
|
|
|
|
|
|
if (!int_set_contains(list, val))
|
|
|
|
return list;
|
|
|
|
|
|
|
|
res = lp_alloc(pool, list->length + sizeof(struct adata) - 4);
|
|
|
|
res->length = list->length-4;
|
|
|
|
|
2000-04-17 11:49:41 +00:00
|
|
|
l = (u32 *) list->data;
|
|
|
|
k = (u32 *) res->data;
|
2000-04-17 11:34:38 +00:00
|
|
|
for (i=0; i<list->length/4; i++)
|
|
|
|
if (l[i] != val)
|
|
|
|
*k++ = l[i];
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|