capa_mp_v4.afi = AFI_IPv4;
capa_mp_v4.afi = htons(AFI_IPv4);
session_open(struct peer *p){	struct msg_open		 msg;	struct buf		*buf;	struct mrt_config	*mrt;	u_int16_t		 len;	int			 errs = 0;	u_int8_t		 op_type, op_len = 0, optparamlen = 0;	u_int8_t		 capa_code, capa_len;	struct capa_mp		 capa_mp_v4;	if (p->capa.announce) {		if (p->capa.ann_mp) {			/* multiprotocol extensions, RFC 2858 */			bzero(&capa_mp_v4, sizeof(capa_mp_v4));			capa_mp_v4.afi = AFI_IPv4;			capa_mp_v4.safi = SAFI_UNICAST;			op_len += 6;	/* 1 code + 1 len + 4 data */		}		if (p->capa.ann_refresh) {			/* route refresh, RFC 2918 */			op_len += 2;	/* 1 code + 1 len, no data */		}		if (op_len > 0)			optparamlen = sizeof(op_type) + sizeof(op_len) + op_len;	}	len = MSGSIZE_OPEN_MIN + optparamlen;	memset(&msg.header.marker, 0xff, sizeof(msg.header.marker));	msg.header.len = htons(len);	msg.header.type = OPEN;	msg.version = 4;	msg.myas = htons(conf->as);	if (p->conf.holdtime)		msg.holdtime = htons(p->conf.holdtime);	else		msg.holdtime = htons(conf->holdtime);	msg.bgpid = conf->bgpid;	/* is already in network byte order */	msg.optparamlen = optparamlen;	if ((buf = buf_open(len)) == NULL) {		bgp_fsm(p, EVNT_CON_FATAL);		return;	}	errs += buf_add(buf, &msg.header.marker, sizeof(msg.header.marker));	errs += buf_add(buf, &msg.header.len, sizeof(msg.header.len));	errs += buf_add(buf, &msg.header.type, sizeof(msg.header.type));	errs += buf_add(buf, &msg.version, sizeof(msg.version));	errs += buf_add(buf, &msg.myas, sizeof(msg.myas));	errs += buf_add(buf, &msg.holdtime, sizeof(msg.holdtime));	errs += buf_add(buf, &msg.bgpid, sizeof(msg.bgpid));	errs += buf_add(buf, &msg.optparamlen, sizeof(msg.optparamlen));	if (p->capa.announce && optparamlen) {		op_type = OPT_PARAM_CAPABILITIES;		errs += buf_add(buf, &op_type, sizeof(op_type));		errs += buf_add(buf, &op_len, sizeof(op_len));		if (p->capa.ann_mp) {			/* multiprotocol extensions, RFC 2858 */			capa_code = CAPA_MP;			capa_len = 4;			errs += buf_add(buf, &capa_code, sizeof(capa_code));			errs += buf_add(buf, &capa_len, sizeof(capa_len));			errs += buf_add(buf, &capa_mp_v4.afi,			    sizeof(capa_mp_v4.afi));			errs += buf_add(buf, &capa_mp_v4.pad,			    sizeof(capa_mp_v4.pad));			errs += buf_add(buf, &capa_mp_v4.safi,			    sizeof(capa_mp_v4.safi));		}		if (p->capa.ann_refresh) {			/* route refresh, RFC 2918 */			capa_code = CAPA_REFRESH;			capa_len = 0;			errs += buf_add(buf, &capa_code, sizeof(capa_code));			errs += buf_add(buf, &capa_len, sizeof(capa_len));		}	}	if (errs == 0) {		LIST_FOREACH(mrt, &mrt_l, list) {			if (mrt->type != MRT_ALL_OUT)				continue;			if ((mrt->peer_id == 0 && mrt->group_id == 0) ||			    mrt->peer_id == p->conf.id ||			    mrt->group_id == p->conf.groupid)				mrt_dump_bgp_msg(mrt, buf->buf, len,				    &p->conf, conf);		}		if (buf_close(&p->wbuf, buf) == -1) {			log_peer_warn(&p->conf, "session_open buf_close");			buf_free(buf);			bgp_fsm(p, EVNT_CON_FATAL);			return;		}	} else {		buf_free(buf);		bgp_fsm(p, EVNT_CON_FATAL);		return;	}	p->stats.msg_sent_open++;}