mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-05 08:31:53 +00:00
tmp: add new helper function
This commit is contained in:
parent
fb2e47d566
commit
d4d925cbea
@ -163,6 +163,17 @@ snmp_put_str(byte *buf, const char *str)
|
|||||||
return buf + snmp_str_size(str);
|
return buf + snmp_str_size(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte *
|
||||||
|
snmp_put_ip4(byte *buf, ip_addr addr)
|
||||||
|
{
|
||||||
|
/* octet string has size 4 bytes */
|
||||||
|
STORE_PTR(buf, 4);
|
||||||
|
|
||||||
|
put_u32(buf+4, ipa_to_u32(addr));
|
||||||
|
|
||||||
|
return buf + 8;
|
||||||
|
}
|
||||||
|
|
||||||
byte *
|
byte *
|
||||||
snmp_put_blank(byte *buf)
|
snmp_put_blank(byte *buf)
|
||||||
{
|
{
|
||||||
@ -258,25 +269,35 @@ void snmp_oid_dump(struct oid *oid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** snmp_oid_compare - find the lexicographical order relation between @left and @right
|
/** snmp_oid_compare - find the lexicographical order relation between @left and @right
|
||||||
|
* both @left and @right has to be non-blank.
|
||||||
* @left: left object id relation operant
|
* @left: left object id relation operant
|
||||||
* @right: right object id relation operant
|
* @right: right object id relation operant
|
||||||
*
|
*
|
||||||
* function returns 0 if left == right -1 if left < right and 1 otherwise
|
* function returns 0 if left == right,
|
||||||
|
* -1 if left < right,
|
||||||
|
* and 1 otherwise
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
snmp_oid_compare(struct oid *left, struct oid *right)
|
snmp_oid_compare(struct oid *left, struct oid *right)
|
||||||
{
|
{
|
||||||
const u32 INTERNET_PREFIX[] = {1, 3, 6, 1};
|
const u32 INTERNET_PREFIX[] = {1, 3, 6, 1};
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (snmp_is_oid_empty(left) && snmp_is_oid_empty(right))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (snmp_is_oid_empty(right))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (snmp_is_oid_empty(left))
|
||||||
|
return 1;
|
||||||
|
*/
|
||||||
|
|
||||||
if (left->prefix == 0 && right->prefix == 0)
|
if (left->prefix == 0 && right->prefix == 0)
|
||||||
goto test_ids;
|
goto test_ids;
|
||||||
|
|
||||||
if (right->prefix == 0)
|
if (right->prefix == 0)
|
||||||
{
|
return (-1) * snmp_oid_compare(right, left);
|
||||||
struct oid *temp = left;
|
|
||||||
left = right;
|
|
||||||
right = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (left->prefix == 0)
|
if (left->prefix == 0)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,8 @@ byte *snmp_put_str(byte *buf, const char *str);
|
|||||||
byte *snmp_put_blank(byte *buf);
|
byte *snmp_put_blank(byte *buf);
|
||||||
byte *snmp_put_oid(byte *buf, struct oid *oid);
|
byte *snmp_put_oid(byte *buf, struct oid *oid);
|
||||||
|
|
||||||
|
byte *snmp_put_ip4(byte *buf, ip_addr ip4);
|
||||||
|
|
||||||
byte *snmp_put_fbyte(byte *buf, u8 data);
|
byte *snmp_put_fbyte(byte *buf, u8 data);
|
||||||
|
|
||||||
void snmp_oid_ip4_index(struct oid *o, uint start, ip4_addr addr);
|
void snmp_oid_ip4_index(struct oid *o, uint start, ip4_addr addr);
|
||||||
|
Loading…
Reference in New Issue
Block a user