if (rv != 0) return (rv);
dispatch_imsg(struct imsgbuf *ibuf, int idx){	struct imsg		 imsg;	int			 n;	if ((n = imsg_read(ibuf)) == -1)		return (-1);	if (n == 0) {	/* connection closed */		log_warnx("dispatch_imsg in main: pipe closed");		return (-1);	}	for (;;) {		if ((n = imsg_get(ibuf, &imsg)) == -1)			return (-1);		if (n == 0)			break;		switch (imsg.hdr.type) {		case IMSG_KROUTE_CHANGE:			if (idx != PFD_PIPE_ROUTE)				log_warnx("route request not from RDE");			else if (kr_change(imsg.data))				return (-1);			break;		case IMSG_KROUTE_DELETE:			if (idx != PFD_PIPE_ROUTE)				log_warnx("route request not from RDE");			else if (kr_delete(imsg.data))				return (-1);			break;		case IMSG_NEXTHOP_ADD:			if (idx != PFD_PIPE_ROUTE)				log_warnx("nexthop request not from RDE");			else				if (imsg.hdr.len != IMSG_HEADER_SIZE +				    sizeof(struct bgpd_addr))					log_warnx("wrong imsg len");				else if (kr_nexthop_add(imsg.data) == -1)					return (-1);			break;		case IMSG_NEXTHOP_REMOVE:			if (idx != PFD_PIPE_ROUTE)				log_warnx("nexthop request not from RDE");			else				if (imsg.hdr.len != IMSG_HEADER_SIZE +				    sizeof(struct bgpd_addr))					log_warnx("wrong imsg len");				else					kr_nexthop_delete(imsg.data);			break;		case IMSG_PFTABLE_ADD:			if (idx != PFD_PIPE_ROUTE)				log_warnx("pftable request not from RDE");			else				if (imsg.hdr.len != IMSG_HEADER_SIZE +				    sizeof(struct pftable_msg))					log_warnx("wrong imsg len");				else if (pftable_addr_add(imsg.data) != 0)					return (-1);			break;		case IMSG_PFTABLE_REMOVE:			if (idx != PFD_PIPE_ROUTE)				log_warnx("pftable request not from RDE");			else				if (imsg.hdr.len != IMSG_HEADER_SIZE +				    sizeof(struct pftable_msg))					log_warnx("wrong imsg len");				else if (pftable_addr_remove(imsg.data) != 0)					return (-1);			break;		case IMSG_PFTABLE_COMMIT:			if (idx != PFD_PIPE_ROUTE)				log_warnx("pftable request not from RDE");			else				if (imsg.hdr.len != IMSG_HEADER_SIZE)					log_warnx("wrong imsg len");				else if (pftable_commit() != 0)					return (-1);			break;		case IMSG_CTL_RELOAD:			if (idx != PFD_PIPE_SESSION)				log_warnx("reload request not from SE");			else				reconfig = 1;			break;		case IMSG_CTL_FIB_COUPLE:			if (idx != PFD_PIPE_SESSION)				log_warnx("couple request not from SE");			else				kr_fib_couple();			break;		case IMSG_CTL_FIB_DECOUPLE:			if (idx != PFD_PIPE_SESSION)				log_warnx("decouple request not from SE");			else				kr_fib_decouple();			break;		case IMSG_CTL_KROUTE:		case IMSG_CTL_KROUTE_ADDR:		case IMSG_CTL_SHOW_NEXTHOP:		case IMSG_CTL_SHOW_INTERFACE:			if (idx != PFD_PIPE_SESSION)				log_warnx("kroute request not from SE");			else				kr_show_route(&imsg);			break;		case IMSG_IFINFO:			if (idx != PFD_PIPE_SESSION)				log_warnx("IFINFO request not from SE");			else if (imsg.hdr.len != IMSG_HEADER_SIZE + IFNAMSIZ)				log_warnx("IFINFO request with wrong len");			else				kr_ifinfo(imsg.data);			break;		default:			break;		}		imsg_free(&imsg);	}	return (0);}