本文整理汇总了C++中PSIZE函数的典型用法代码示例。如果您正苦于以下问题:C++ PSIZE函数的具体用法?C++ PSIZE怎么用?C++ PSIZE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PSIZE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zebra_route
static int
zebra_route(proto_tree *tree, tvbuff_t *tvb, int offset, guint16 len,
guint8 family)
{
guint32 prefix4;
guint8 message, prefixlen, buffer6[16];
proto_tree_add_item(tree, hf_zebra_type, tvb,
offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
offset, 1, ENC_BIG_ENDIAN);
offset += 1;
message = tvb_get_guint8(tvb, offset);
offset = zebra_route_message(tree, tvb, offset, message);
prefixlen = tvb_get_guint8(tvb, offset);
proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
offset, 1, prefixlen);
offset += 1;
if (family == ZEBRA_FAMILY_IPV6) {
memset(buffer6, '\0', sizeof buffer6);
tvb_memcpy(tvb, buffer6, offset,
MIN((unsigned) PSIZE(prefixlen), sizeof buffer6));
proto_tree_add_ipv6(tree, hf_zebra_prefix6,
tvb, offset, PSIZE(prefixlen), buffer6);
}else {
prefix4 = 0;
tvb_memcpy(tvb, (guint8 *)&prefix4, offset,
MIN((unsigned) PSIZE(prefixlen), sizeof prefix4));
proto_tree_add_ipv4(tree, hf_zebra_prefix4,
tvb, offset, PSIZE(prefixlen), prefix4);
}
offset += PSIZE(prefixlen);
if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
offset = zebra_route_nexthop(tree, tvb, offset, len);
}
if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
offset = zebra_route_ifindex(tree, tvb, offset, len);
}
if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
proto_tree_add_item(tree, hf_zebra_distance,
tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
}
if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
proto_tree_add_item(tree, hf_zebra_metric,
tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
}
return offset;
}
示例2: zapi_ipv4_route
/*
* "xdr_encode"-like interface that allows daemon (client) to send
* a message to zebra server for a route that needs to be
* added/deleted to the kernel. Info about the route is specified
* by the caller in a struct zapi_ipv4. zapi_ipv4_read() then writes
* the info down the zclient socket using the stream_* functions.
*
* The corresponding read ("xdr_decode") function on the server
* side is zread_ipv4_add()/zread_ipv4_delete().
*
* 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Length (2) | Command | Route Type |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | ZEBRA Flags | Message Flags | Prefix length |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Destination IPv4 Prefix for route |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Nexthop count |
* +-+-+-+-+-+-+-+-+
*
*
* A number of IPv4 nexthop(s) or nexthop interface index(es) are then
* described, as per the Nexthop count. Each nexthop described as:
*
* +-+-+-+-+-+-+-+-+
* | Nexthop Type | Set to one of ZEBRA_NEXTHOP_*
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | IPv4 Nexthop address or Interface Index number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* Alternatively, if the flags field has ZEBRA_FLAG_BLACKHOLE or
* ZEBRA_FLAG_REJECT is set then Nexthop count is set to 1, then _no_
* nexthop information is provided, and the message describes a prefix
* to blackhole or reject route.
*
* If ZAPI_MESSAGE_DISTANCE is set, the distance value is written as a 1
* byte value.
*
* If ZAPI_MESSAGE_METRIC is set, the metric value is written as an 8
* byte value.
*
* XXX: No attention paid to alignment.
*/
int
zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p,
struct zapi_ipv4 *api)
{
int i;
int psize;
struct stream *s;
/* Reset stream. */
s = zclient->obuf;
stream_reset (s);
zclient_create_header (s, cmd);
/* Put type and nexthop. */
stream_putc (s, api->type);
stream_putc (s, api->flags);
stream_putc (s, api->message);
stream_putw (s, api->safi);
/* Put prefix information. */
psize = PSIZE (p->prefixlen);
stream_putc (s, p->prefixlen);
stream_write (s, (u_char *) & p->prefix, psize);
/* Nexthop, ifindex, distance and metric information. */
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
{
if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE))
{
stream_putc (s, 1);
stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
/* XXX assert(api->nexthop_num == 0); */
/* XXX assert(api->ifindex_num == 0); */
}
else
stream_putc (s, api->nexthop_num + api->ifindex_num);
for (i = 0; i < api->nexthop_num; i++)
{
stream_putc (s, ZEBRA_NEXTHOP_IPV4);
stream_put_in_addr (s, api->nexthop[i]);
}
for (i = 0; i < api->ifindex_num; i++)
{
stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
stream_putl (s, api->ifindex[i]);
}
}
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE))
stream_putc (s, api->distance);
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_METRIC))
stream_putl (s, api->metric);
/* Put length at the first point of the stream. */
//.........这里部分代码省略.........
示例3: bgp_nlri_parse_6pe
s32 bgp_nlri_parse_6pe (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
{
u_char *pnt;
u_char *lim;
struct prefix p;
int psize;
int prefixlen;
u_int32_t label;
u_char *tagpnt;
/* Check peer status. */
if (peer->status != Established)
return 0;
pnt = packet->nlri;
lim = pnt + packet->length;
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
memset (&p, 0, sizeof (struct prefix));
/* Fetch prefix length. */
prefixlen = *pnt++;
p.family = AF_INET6;
psize = PSIZE (prefixlen);
if (prefixlen < 24)
{
zlog_err ("prefix length is less than 88: %d", prefixlen);
return -1;
}
label = decode_label (pnt);
/* Copyr label to prefix. */
tagpnt = pnt;
p.prefixlen = prefixlen - 24;
memcpy (&p.u.prefix, pnt + 3, psize - 3);
if (pnt + psize > lim)
return -1;
if (attr)
bgp_update (peer, &p, attr, AFI_IP6, SAFI_UNICAST,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, tagpnt, 0);
else
bgp_withdraw (peer, &p, attr, AFI_IP6, SAFI_UNICAST,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, tagpnt);
}
/* Packet length consistency check. */
if (pnt != lim)
return -1;
return 0;
}
示例4: check_entry
check_entry(u64 va, u64 ps, char *str)
{
va &= ~ (PSIZE(ps)-1);
if ( va == 0x2000000002908000UL ||
va == 0x600000000000C000UL ) {
stop();
}
if (tlb_debug) printk("%s at %lx %lx\n", str, va, 1UL<<ps);
}
示例5: rip_zebra_read_ipv4
/* Zebra route add and delete treatment. */
static int
rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length)
{
struct stream *s;
struct zapi_ipv4 api;
unsigned long ifindex;
struct in_addr nexthop;
struct prefix_ipv4 p;
s = zclient->ibuf;
ifindex = 0;
nexthop.s_addr = 0;
/* Type, flags, message. */
api.type = stream_getc (s);
api.flags = stream_getc (s);
api.message = stream_getc (s);
/* IPv4 prefix. */
memset (&p, 0, sizeof (struct prefix_ipv4));
p.family = AF_INET;
p.prefixlen = stream_getc (s);
stream_get (&p.prefix, s, PSIZE (p.prefixlen));
/* Nexthop, ifindex, distance, metric. */
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
{
api.nexthop_num = stream_getc (s);
nexthop.s_addr = stream_get_ipv4 (s);
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
{
api.ifindex_num = stream_getc (s);
ifindex = stream_getl (s);
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
api.distance = stream_getc (s);
else
api.distance = 255;
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
api.metric = stream_getl (s);
else
api.metric = 0;
/* Then fetch IPv4 prefixes. */
if (command == ZEBRA_IPV4_ROUTE_ADD)
rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
&nexthop, api.metric, api.distance);
else
rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
return 0;
}
示例6: zapi_ipv6_route
int
zapi_ipv6_route (u_char cmd, struct_zclient *zclient, struct prefix_ipv6 *p,
struct zapi_ipv6 *api)
{
int i;
int psize;
struct stream *s;
/* Reset stream. */
s = zclient->obuf;
stream_reset (s);
/* Length place holder. */
stream_putw (s, 0);
/* Put command, type and nexthop. */
stream_putc (s, cmd);
stream_putc (s, api->type);
stream_putc (s, api->flags);
stream_putc (s, api->message);
/* Put prefix information. */
psize = PSIZE (p->prefixlen);
stream_putc (s, p->prefixlen);
stream_write (s, (u_char *)&p->prefix, psize);
/* Nexthop, ifindex, distance and metric information. */
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
{
stream_putc (s, api->nexthop_num + api->ifindex_num);
for (i = 0; i < api->nexthop_num; i++)
{
stream_putc (s, ZEBRA_NEXTHOP_IPV6);
stream_write (s, (u_char *)api->nexthop[i], 16);
}
for (i = 0; i < api->ifindex_num; i++)
{
stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
stream_putl (s, api->ifindex[i]);
}
}
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE))
stream_putc (s, api->distance);
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_METRIC))
stream_putl (s, api->metric);
/* Put length at the first point of the stream. */
stream_putw_at (s, 0, stream_get_endp (s));
return writen (zclient->sock, s->data, stream_get_endp (s));
}
示例7: ripng_zebra_read_ipv6
/* Zebra route add and delete treatment. */
int
ripng_zebra_read_ipv6 (int command, struct zclient *zclient,
zebra_size_t length)
{
struct stream *s;
struct zapi_ipv6 api;
unsigned long ifindex;
struct in6_addr nexthop;
struct prefix_ipv6 p;
s = zclient->ibuf;
ifindex = 0;
memset (&nexthop, 0, sizeof (struct in6_addr));
/* Type, flags, message. */
api.type = stream_getc (s);
api.flags = stream_getc (s);
api.message = stream_getc (s);
/* IPv6 prefix. */
memset (&p, 0, sizeof (struct prefix_ipv6));
p.family = AF_INET6;
p.prefixlen = stream_getc (s);
stream_get (&p.prefix, s, PSIZE (p.prefixlen));
/* Nexthop, ifindex, distance, metric. */
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
{
api.nexthop_num = stream_getc (s);
stream_get (&nexthop, s, 16);
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
{
api.ifindex_num = stream_getc (s);
ifindex = stream_getl (s);
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
api.distance = stream_getc (s);
else
api.distance = 0;
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
api.metric = stream_getl (s);
else
api.metric = 0;
if (command == ZEBRA_IPV6_ROUTE_ADD)
ripng_redistribute_add (api.type, 0, &p, ifindex);
else
ripng_redistribute_delete (api.type, 0, &p, ifindex);
return 0;
}
示例8: babel_zebra_read_ipv4
static int
babel_zebra_read_ipv4 (int command, struct zclient *zclient,
zebra_size_t length)
{
struct stream *s;
struct zapi_ipv4 api;
unsigned long ifindex = -1;
struct in_addr nexthop;
struct prefix_ipv4 prefix;
s = zclient->ibuf;
ifindex = 0;
memset (&nexthop, 0, sizeof (struct in_addr));
memset (&api, 0, sizeof(struct zapi_ipv4));
memset (&prefix, 0, sizeof (struct prefix_ipv4));
/* Type, flags, message. */
api.type = stream_getc (s);
api.flags = stream_getc (s);
api.message = stream_getc (s);
/* IPv6 prefix. */
prefix.family = AF_INET;
prefix.prefixlen = stream_getc (s);
stream_get (&prefix.prefix, s, PSIZE (prefix.prefixlen));
/* Nexthop, ifindex, distance, metric. */
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) {
api.nexthop_num = stream_getc (s);
stream_get (&nexthop, s, sizeof(nexthop));
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) {
api.ifindex_num = stream_getc (s);
ifindex = stream_getl (s);
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
api.distance = stream_getc (s);
else
api.distance = 0;
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
api.metric = stream_getl (s);
else
api.metric = 0;
if (command == ZEBRA_IPV6_ROUTE_ADD) {
babel_ipv4_route_add(&api, &prefix, ifindex, &nexthop);
} else {
babel_ipv4_route_delete(&api, &prefix, ifindex);
}
return 0;
}
示例9: isis_zebra_read_ipv4
int
isis_zebra_read_ipv4 (int command, struct zclient *zclient,
zebra_size_t length)
{
struct stream *stream;
struct zapi_ipv4 api;
struct prefix_ipv4 p;
unsigned long ifindex;
struct in_addr nexthop;
stream = zclient->ibuf;
memset (&p, 0, sizeof (struct prefix_ipv4));
ifindex = 0;
api.type = stream_getc (stream);
api.flags = stream_getc (stream);
api.message = stream_getc (stream);
p.family = AF_INET;
p.prefixlen = stream_getc (stream);
stream_get (&p.prefix, stream, PSIZE (p.prefixlen));
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
{
api.nexthop_num = stream_getc (stream);
nexthop.s_addr = stream_get_ipv4 (stream);
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
{
api.ifindex_num = stream_getc (stream);
ifindex = stream_getl (stream);
}
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
api.distance = stream_getc (stream);
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
api.metric = stream_getl (stream);
else
api.metric = 0;
if (command == ZEBRA_IPV4_ROUTE_ADD)
{
zlog_debug ("IPv4 Route add from Z");
}
return 0;
}
示例10: isis_find_vertex
static struct isis_vertex *
isis_find_vertex (struct list *list, void *id, enum vertextype vtype)
{
struct listnode *node;
struct isis_vertex *vertex;
struct prefix *p1, *p2;
for (ALL_LIST_ELEMENTS_RO (list, node, vertex))
{
if (vertex->type != vtype)
continue;
switch (vtype)
{
case VTYPE_ES:
case VTYPE_NONPSEUDO_IS:
case VTYPE_NONPSEUDO_TE_IS:
if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN) == 0)
return vertex;
break;
case VTYPE_PSEUDO_IS:
case VTYPE_PSEUDO_TE_IS:
if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN + 1) == 0)
return vertex;
break;
case VTYPE_IPREACH_INTERNAL:
case VTYPE_IPREACH_EXTERNAL:
case VTYPE_IPREACH_TE:
#ifdef HAVE_IPV6
case VTYPE_IP6REACH_INTERNAL:
case VTYPE_IP6REACH_EXTERNAL:
#endif /* HAVE_IPV6 */
p1 = (struct prefix *) id;
p2 = (struct prefix *) &vertex->N.id;
if (p1->family == p2->family && p1->prefixlen == p2->prefixlen &&
memcmp (&p1->u.prefix, &p2->u.prefix,
PSIZE (p1->prefixlen)) == 0)
return vertex;
break;
}
}
return NULL;
}
示例11: logic_pinger_http_get_data
unsigned logic_pinger_http_get_data(unsigned pkt, unsigned more_data)
{
char buf[1024];
char *dest = buf;
if(more_data == 0)
{
dest+=sprintf((char*)dest,"var pinger_packfmt={");
PLINK(dest, logic_pinger_setup[0], ip);
PLINK(dest, logic_pinger_setup[0], period);
PLINK(dest, logic_pinger_setup[0], timeout);
#ifdef DNS_MODULE
PLINK(dest, logic_pinger_setup[0], hostname);
#endif
PSIZE(dest, sizeof logic_pinger_setup[0]); // must be the last // size must be word-aligned!
dest += sprintf(dest, "}; var pinger_data=[");
}
struct logic_pinger_setup_s *setup;
for(;more_data<LOGIC_MAX_PINGER;)
{
setup = &logic_pinger_setup[more_data];
*dest++ = '{';
PDATA_IP(dest, (*setup), ip);
PDATA(dest, (*setup), period);
PDATA(dest, (*setup), timeout);
#ifdef DNS_MODULE
PDATA_PASC_STR(dest, (*setup), hostname);
#endif
--dest; // clear last PDATA-created comma
*dest++ = '}';
*dest++ = ',';
++more_data;
if(dest - buf > sizeof buf - 128) break; // data buffer capacity used up to 80%
}
if(more_data == LOGIC_MAX_PINGER)
{
more_data = 0; // reset pumping
--dest; // remove last comma
*dest++ = ']';
*dest++ = ';';
}
tcp_put_tx_body(pkt, (unsigned char*)buf, dest - buf);
return more_data;
}
示例12: zebra_read_ipv6
void
zebra_read_ipv6 (int command, struct zserv *client, u_short length)
{
u_char type;
u_char flags;
struct in6_addr nexthop, *gate;
u_char *lim;
u_char *pnt;
unsigned int ifindex;
pnt = stream_pnt (client->ibuf);
lim = pnt + length;
type = stream_getc (client->ibuf);
flags = stream_getc (client->ibuf);
stream_get (&nexthop, client->ibuf, sizeof (struct in6_addr));
while (stream_pnt (client->ibuf) < lim)
{
int size;
struct prefix_ipv6 p;
ifindex = stream_getl (client->ibuf);
memset (&p, 0, sizeof (struct prefix_ipv6));
p.family = AF_INET6;
p.prefixlen = stream_getc (client->ibuf);
size = PSIZE(p.prefixlen);
stream_get (&p.prefix, client->ibuf, size);
if (IN6_IS_ADDR_UNSPECIFIED (&nexthop))
gate = NULL;
else
gate = &nexthop;
if (command == ZEBRA_IPV6_ROUTE_ADD)
rib_add_ipv6 (type, flags, &p, gate, ifindex, 0, 0, 0);
else
rib_delete_ipv6 (type, flags, &p, gate, ifindex, 0);
}
}
示例13: logic_http_get_data
unsigned logic_http_get_data(unsigned pkt, unsigned more_data)
{
char buf[1024];
char *dest = buf;
if(more_data == 0)
{
dest+=sprintf((char*)dest,"var packfmt={");
PLINK(dest, logic_setup[0], flags);
PLINK(dest, logic_setup[0], input);
PLINK(dest, logic_setup[0], condition);
PLINK(dest, logic_setup[0], action);
PLINK(dest, logic_setup[0], output);
PSIZE(dest, sizeof logic_setup[0]); // must be the last // size must be word-aligned!
dest += sprintf(dest, "}; var data_logic_flags=%u; var data=[", logic_flags);
}
struct logic_setup_s *setup;
for(;more_data<LOGIC_MAX_RULES;)
{
setup = &logic_setup[more_data];
*dest++ = '{';
PDATA(dest, (*setup), flags);
PDATA(dest, (*setup), input);
PDATA(dest, (*setup), condition);
PDATA(dest, (*setup), action);
PDATA(dest, (*setup), output);
--dest; // clear last PDATA-created comma
*dest++ = '}';
*dest++ = ',';
++more_data;
if(dest - buf > sizeof buf - 128) break; // data buffer capacity used up to 80%
}
if(more_data == LOGIC_MAX_RULES)
{
more_data = 0; // reset pumping
--dest; // remove last comma
*dest++ = ']';
*dest++ = ';';
}
tcp_put_tx_body(pkt, (unsigned char*)buf, dest - buf);
return more_data;
}
示例14: tstat_http_get_data
unsigned tstat_http_get_data(unsigned pkt, unsigned more_data)
{
char buf[1024];
char *dest = buf;
if(more_data == 0)
{
dest+=sprintf((char*)dest,"var tstat_packfmt={");
PLINK(dest, tstat_setup[0], setpoint);
PLINK(dest, tstat_setup[0], hyst);
PLINK(dest, tstat_setup[0], sensor_no);
PSIZE(dest, sizeof tstat_setup[0]); // must be the last // size must be word-aligned!
dest += sprintf(dest, "}; var tstat_data=[");
}
struct tstat_setup_s *setup;
for(;more_data<TSTAT_MAX_CHANNEL;)
{
setup = &tstat_setup[more_data];
*dest++ = '{';
PDATA_SIGNED(dest, (*setup), setpoint);
PDATA(dest, (*setup), hyst);
PDATA(dest, (*setup), sensor_no);
--dest; // clear last PDATA-created comma
*dest++ = '}';
*dest++ = ',';
++more_data;
if(dest - buf > sizeof buf - 128) break; // data buffer capacity used up to 80%
}
if(more_data == TSTAT_MAX_CHANNEL)
{
more_data = 0; // reset pumping
--dest; // remove last comma
dest += sprintf(dest, "]; var termo_n_ch=%u;", TERMO_N_CH);
}
tcp_put_tx_body(pkt, (unsigned char*)buf, dest - buf);
return more_data;
}
示例15: zsend_route_multipath
/*
* The zebra server sends the clients a ZEBRA_IPV4_ROUTE_ADD or a
* ZEBRA_IPV6_ROUTE_ADD via zsend_route_multipath in the following
* situations:
* - when the client starts up, and requests default information
* by sending a ZEBRA_REDISTRIBUTE_DEFAULT_ADD to the zebra server, in the
* - case of rip, ripngd, ospfd and ospf6d, when the client sends a
* ZEBRA_REDISTRIBUTE_ADD as a result of the "redistribute" vty cmd,
* - when the zebra server redistributes routes after it updates its rib
*
* The zebra server sends clients a ZEBRA_IPV4_ROUTE_DELETE or a
* ZEBRA_IPV6_ROUTE_DELETE via zsend_route_multipath when:
* - a "ip route" or "ipv6 route" vty command is issued, a prefix is
* - deleted from zebra's rib, and this info
* has to be redistributed to the clients
*
* XXX The ZEBRA_IPV*_ROUTE_ADD message is also sent by the client to the
* zebra server when the client wants to tell the zebra server to add a
* route to the kernel (zapi_ipv4_add etc. ). Since it's essentially the
* same message being sent back and forth, this function and
* zapi_ipv{4,6}_{add, delete} should be re-written to avoid code
* duplication.
*/
int
zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p,
struct rib *rib)
{
int psize;
struct stream *s;
struct nexthop *nexthop;
unsigned long nhnummark = 0;
int nhnum = 0;
u_char zapi_flags = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_IFINDEX;
s = client->obuf;
stream_reset (s);
/* Place holder for size. */
stream_putw (s, 0);
/* Put command, type and nexthop. */
stream_putc (s, cmd);
stream_putc (s, rib->type);
stream_putc (s, rib->flags);
/*
* XXX no need to set ZAPI_MESSAGE_NEXTHOP if we are going to
* send empty nexthop?
*/
if (cmd == ZEBRA_IPV4_ROUTE_ADD || ZEBRA_IPV6_ROUTE_ADD)
zapi_flags |= ZAPI_MESSAGE_METRIC;
stream_putc (s, zapi_flags);
/* Prefix. */
psize = PSIZE (p->prefixlen);
stream_putc (s, p->prefixlen);
stream_write (s, (u_char *) & p->u.prefix, psize);
/*
* XXX The message format sent by zebra below does not match the format
* of the corresponding message expected by the zebra server
* itself (e.g., see zread_ipv4_add). The nexthop_num is not set correctly,
* (is there a bug on the client side if more than one segment is sent?)
* nexthop ZEBRA_NEXTHOP_IPV4 is never set, ZEBRA_NEXTHOP_IFINDEX
* is hard-coded.
*/
/* Nexthop */
for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
{
if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
{
nhnummark = stream_get_putp (s);
stream_putc (s, 1); /* placeholder */
nhnum++;
switch(nexthop->type)
{
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
stream_put_in_addr (s, &nexthop->gate.ipv4);
break;
#ifdef HAVE_IPV6
case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX:
case NEXTHOP_TYPE_IPV6_IFNAME:
stream_write (s, (u_char *) &nexthop->gate.ipv6, 16);
break;
#endif
default:
if (cmd == ZEBRA_IPV4_ROUTE_ADD
|| cmd == ZEBRA_IPV4_ROUTE_DELETE)
{
struct in_addr empty;
memset (&empty, 0, sizeof (struct in_addr));
stream_write (s, (u_char *) &empty, IPV4_MAX_BYTELEN);
}
else
{
struct in6_addr empty;
//.........这里部分代码省略.........