From 2398992d52df0dd6e33114c4246932a49ac51249 Mon Sep 17 00:00:00 2001 From: Tyler Li Date: Fri, 22 May 2020 00:12:51 +0800 Subject: [PATCH] [iccpd] build iccpd deb by auto tools (#4540) * [iccpd] build iccpd deb by auto tools --- dockers/docker-iccpd/Dockerfile.j2 | 1 - rules/docker-iccpd.mk | 12 +++++-- rules/iccpd.mk | 14 +++++--- src/iccpd/Makefile | 37 ------------------- src/iccpd/Makefile.am | 1 + src/iccpd/autogen.sh | 6 ++++ src/iccpd/configure.ac | 32 +++++++++++++++++ src/iccpd/debian/DEBIAN/control | 12 ------- src/iccpd/debian/changelog | 6 ++++ src/iccpd/debian/compat | 1 + src/iccpd/debian/control | 18 ++++++++++ src/iccpd/debian/rules | 34 ++++++++++++++++++ src/iccpd/include/iccp_csm.h | 1 + src/iccpd/include/scheduler.h | 1 + src/iccpd/src/Makefile | 55 ----------------------------- src/iccpd/src/Makefile.am | 22 ++++++++++++ src/iccpd/src/iccp_ifm.c | 2 +- src/iccpd/src/mclagdctl/Makefile | 28 --------------- src/iccpd/src/mclagdctl/Makefile.am | 10 ++++++ src/iccpd/src/mclagdctl/mclagdctl.c | 4 ++- src/iccpd/src/mlacp_sync_prepare.c | 2 +- src/iccpd/src/port.c | 2 ++ src/iccpd/src/scheduler.c | 5 ++- 23 files changed, 163 insertions(+), 143 deletions(-) delete mode 100644 src/iccpd/Makefile create mode 100644 src/iccpd/Makefile.am create mode 100755 src/iccpd/autogen.sh create mode 100644 src/iccpd/configure.ac delete mode 100644 src/iccpd/debian/DEBIAN/control create mode 100644 src/iccpd/debian/changelog create mode 100644 src/iccpd/debian/compat create mode 100644 src/iccpd/debian/control create mode 100755 src/iccpd/debian/rules delete mode 100644 src/iccpd/src/Makefile create mode 100644 src/iccpd/src/Makefile.am delete mode 100644 src/iccpd/src/mclagdctl/Makefile create mode 100644 src/iccpd/src/mclagdctl/Makefile.am diff --git a/dockers/docker-iccpd/Dockerfile.j2 b/dockers/docker-iccpd/Dockerfile.j2 index 3c7e01ed54..3424c0e97f 100644 --- a/dockers/docker-iccpd/Dockerfile.j2 +++ b/dockers/docker-iccpd/Dockerfile.j2 @@ -9,7 +9,6 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ apt-get install -y ebtables -RUN apt-get -y install -f kmod COPY \ {% for deb in docker_iccpd_debs.split(' ') -%} diff --git a/rules/docker-iccpd.mk b/rules/docker-iccpd.mk index da661e9a22..106da8e589 100644 --- a/rules/docker-iccpd.mk +++ b/rules/docker-iccpd.mk @@ -1,14 +1,22 @@ # docker image for iccpd agent -DOCKER_ICCPD = docker-iccpd.gz -$(DOCKER_ICCPD)_PATH = $(DOCKERS_PATH)/docker-iccpd +DOCKER_ICCPD_STEM = docker-iccpd +DOCKER_ICCPD = $(DOCKER_ICCPD_STEM).gz +DOCKER_ICCPD_DBG = $(DOCKER_ICCPD_STEM)-$(DBG_IMAGE_MARK).gz +$(DOCKER_ICCPD)_PATH = $(DOCKERS_PATH)/$(DOCKER_ICCPD_STEM) $(DOCKER_ICCPD)_DEPENDS += $(SWSS) $(REDIS_TOOLS) $(ICCPD) +$(DOCKER_ICCPD)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS) +$(DOCKER_ICCPD)_DBG_DEPENDS += $(SWSS_DBG) $(LIBSWSSCOMMON_DBG) $(ICCPD_DBG) +$(DOCKER_ICCPD)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES) $(DOCKER_ICCPD)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH) ifeq ($(ENABLE_ICCPD), y) SONIC_DOCKER_IMAGES += $(DOCKER_ICCPD) SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_ICCPD) SONIC_STRETCH_DOCKERS += $(DOCKER_ICCPD) +SONIC_DOCKER_DBG_IMAGES += $(DOCKER_ICCPD_DBG) +SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_ICCPD_DBG) +SONIC_STRETCH_DBG_DOCKERS += $(DOCKER_ICCPD_DBG) endif $(DOCKER_ICCPD)_CONTAINER_NAME = iccpd diff --git a/rules/iccpd.mk b/rules/iccpd.mk index 26d3adf1dd..eb97efc52b 100644 --- a/rules/iccpd.mk +++ b/rules/iccpd.mk @@ -6,8 +6,14 @@ ICCPD = iccpd_$(ICCPD_VERSION)_$(CONFIGURED_ARCH).deb $(ICCPD)_DEPENDS += $(LIBNL_GENL3_DEV) $(LIBNL_CLI_DEV) $(ICCPD)_RDEPENDS += $(LIBNL_GENL3) $(LIBNL_CLI) $(ICCPD)_SRC_PATH = $(SRC_PATH)/iccpd -SONIC_MAKE_DEBS += $(ICCPD) +SONIC_DPKG_DEBS += $(ICCPD) -# Export these variables so they can be used in a sub-make -export ICCPD_VERSION -export ICCPD +ICCPD_DBG = iccpd-dbg_$(ICCPD_VERSION)_$(CONFIGURED_ARCH).deb +$(ICCPD_DBG)_DEPENDS += $(ICCPD) +$(ICCPD_DBG)_RDEPENDS += $(ICCPD) +$(eval $(call add_derived_package,$(ICCPD),$(ICCPD_DBG))) + +# The .c, .cpp, .h & .hpp files under src/{$DBG_SRC_ARCHIVE list} +# are archived into debug one image to facilitate debugging. +# +DBG_SRC_ARCHIVE += iccpd diff --git a/src/iccpd/Makefile b/src/iccpd/Makefile deleted file mode 100644 index b8f5c19ddf..0000000000 --- a/src/iccpd/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -.ONESHELL: -SHELL = /bin/bash -.SHELLFLAGS += -e - -MAIN_TARGET = iccpd_$(ICCPD_VERSION)_$(CONFIGURED_ARCH).deb -DEB_PATH = debian - -all: iccpd-build mclagdctl-build - -iccpd-build: - make -C src - -mclagdctl-build: - make -C src/mclagdctl - -$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : - make all - if [ ! -d $(DEB_PATH)/usr/bin ]; then - mkdir -p $(DEB_PATH)/usr/bin - fi - cp iccpd $(DEB_PATH)/usr/bin/iccpd - cp src/mclagdctl/mclagdctl $(DEB_PATH)/usr/bin/mclagdctl - chmod +x $(DEB_PATH)/usr/bin/iccpd - chmod +x $(DEB_PATH)/usr/bin/mclagdctl - md5sum $(DEB_PATH)/usr/bin/iccpd > $(DEB_PATH)/DEBIAN/md5sums - md5sum $(DEB_PATH)/usr/bin/mclagdctl >> $(DEB_PATH)/DEBIAN/md5sums - sed -i "s/Package: .*/Package: iccpd-$(ICCPD_VERSION)-$(CONFIGURED_ARCH)/g" $(DEB_PATH)/DEBIAN/control - sed -i "s/Architecture: .*/Architecture: $(CONFIGURED_ARCH)/g" $(DEB_PATH)/DEBIAN/control - dpkg-deb -b $(DEB_PATH) $(DEST)/$(MAIN_TARGET) - -clean: iccpd-clean mclagdctl-clean - -iccpd-clean: - make -C src clean - -mclagdctl-clean: - make -C src/mclagdctl clean diff --git a/src/iccpd/Makefile.am b/src/iccpd/Makefile.am new file mode 100644 index 0000000000..af437a64d6 --- /dev/null +++ b/src/iccpd/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/src/iccpd/autogen.sh b/src/iccpd/autogen.sh new file mode 100755 index 0000000000..c8d0bbe4a2 --- /dev/null +++ b/src/iccpd/autogen.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +libtoolize --force --copy && +autoreconf --force --install -I m4 +rm -Rf autom4te.cache + diff --git a/src/iccpd/configure.ac b/src/iccpd/configure.ac new file mode 100644 index 0000000000..9567d2b5cd --- /dev/null +++ b/src/iccpd/configure.ac @@ -0,0 +1,32 @@ +AC_INIT([iccpd],[0.5]) +AC_CONFIG_SRCDIR([]) +AC_CONFIG_AUX_DIR(config) +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE([foreign]) +AC_LANG_C +AC_PROG_CC +AC_PROG_LIBTOOL +AC_HEADER_STDC + +AC_ARG_ENABLE(debug, +[ --enable-debug Compile with debugging flags], +[case "${enableval}" in + yes) debug=true ;; + no) debug=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;; +esac],[debug=false]) +AM_CONDITIONAL(DEBUG, test x$debug = xtrue) + +CPPFLAGS="-D_FORTIFY_SOURCE=2" + +CFLAGS_COMMON="-Wno-unused-result" + +AC_SUBST(CFLAGS_COMMON) + +AC_CONFIG_FILES([ + Makefile + src/Makefile + src/mclagdctl/Makefile +]) + +AC_OUTPUT diff --git a/src/iccpd/debian/DEBIAN/control b/src/iccpd/debian/DEBIAN/control deleted file mode 100644 index cedfa03f37..0000000000 --- a/src/iccpd/debian/DEBIAN/control +++ /dev/null @@ -1,12 +0,0 @@ -Package: iccpd-0.0.5-amd64 -Source: nps -Version: 0.0.5 -Architecture: amd64 -Maintainer: Simon Ji -Installed-Size: 1508 -Depends: -Section: main -Priority: extra -Homepage: https://github.com/NephosInc/SONiC -Description: - diff --git a/src/iccpd/debian/changelog b/src/iccpd/debian/changelog new file mode 100644 index 0000000000..a2b3b066bc --- /dev/null +++ b/src/iccpd/debian/changelog @@ -0,0 +1,6 @@ +sonic (0.0.5) stable; urgency=medium + + * Initial release. + + -- Tyler Li Thu, 23 Apr 2020 10:00:00 +0800 + diff --git a/src/iccpd/debian/compat b/src/iccpd/debian/compat new file mode 100644 index 0000000000..f599e28b8a --- /dev/null +++ b/src/iccpd/debian/compat @@ -0,0 +1 @@ +10 diff --git a/src/iccpd/debian/control b/src/iccpd/debian/control new file mode 100644 index 0000000000..3c9334af0a --- /dev/null +++ b/src/iccpd/debian/control @@ -0,0 +1,18 @@ +Source: sonic +Maintainer: Tyler Li +Section: net +Priority: optional +Build-Depends: dh-exec (>=0.3), debhelper (>= 9), autotools-dev +Standards-Version: 0.0.5 + +Package: iccpd +Architecture: any +Depends: ${shlibs:Depends} +Description: This package contains Inter-Chassis Control Protocol for SONiC project. + +Package: iccpd-dbg +Architecture: any +Section: debug +Priority: extra +Depends: iccpd (=${binary:Version}) +Description: debugging symbols for iccpd diff --git a/src/iccpd/debian/rules b/src/iccpd/debian/rules new file mode 100755 index 0000000000..81f4842387 --- /dev/null +++ b/src/iccpd/debian/rules @@ -0,0 +1,34 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + +# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/* +DPKG_EXPORT_BUILDFLAGS = 1 +include /usr/share/dpkg/default.mk + +# see FEATURE AREAS in dpkg-buildflags(1) +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +# main packaging script based on dh7 syntax +%: + dh $@ --with autotools-dev + +# dh_make generated override targets +# This is example for Cmake (See https://bugs.debian.org/641051 ) +#override_dh_auto_configure: +# dh_auto_configure -- \ +# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) + +override_dh_auto_install: + dh_auto_install --destdir=debian/iccpd + +override_dh_strip: + dh_strip --dbg-package=iccpd-dbg diff --git a/src/iccpd/include/iccp_csm.h b/src/iccpd/include/iccp_csm.h index 96e3663719..01e424d132 100644 --- a/src/iccpd/include/iccp_csm.h +++ b/src/iccpd/include/iccp_csm.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "../include/app_csm.h" #include "../include/msg_format.h" diff --git a/src/iccpd/include/scheduler.h b/src/iccpd/include/scheduler.h index b3be274282..a1b31039d7 100644 --- a/src/iccpd/include/scheduler.h +++ b/src/iccpd/include/scheduler.h @@ -35,6 +35,7 @@ #include struct CSM; +struct System; #define CONNECT_INTERVAL_SEC 1 #define CONNECT_TIMEOUT_MSEC 100 diff --git a/src/iccpd/src/Makefile b/src/iccpd/src/Makefile deleted file mode 100644 index 5e8cebc703..0000000000 --- a/src/iccpd/src/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -LIBNL_CFLAGS = -I/usr/include/libnl3 -LIBNL_LIBS = -lnl-cli-3 -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 - -CC = gcc -SOURCES = app_csm.c cmd_option.c iccp_cli.c iccp_cmd_show.c iccp_cmd.c \ -iccp_csm.c iccp_ifm.c iccp_main.c logger.c \ -port.c scheduler.c system.c iccp_consistency_check.c \ -mlacp_link_handler.c \ -mlacp_sync_prepare.c mlacp_sync_update.c\ -mlacp_fsm.c \ -iccp_netlink.c - -OBJECTS = app_csm.o cmd_option.o iccp_cli.o iccp_cmd_show.o iccp_cmd.o \ -iccp_csm.o iccp_ifm.o iccp_main.o logger.o \ -port.o scheduler.o system.o iccp_consistency_check.o\ -mlacp_link_handler.o \ -mlacp_sync_prepare.o mlacp_sync_update.o \ -mlacp_fsm.o \ -iccp_netlink.o - -HEADERS = ../include/app_csm.h ../include/cmd_option.h ../include/iccp_cli.h \ -../include/iccp_cmd_show.h \ -../include/iccp_csm.h ../include/iccp_ifm.h \ -../include/logger.h ../include/mlacp_fsm.h \ -../include/mlacp_tlv.h ../include/msg_format.h ../include/port.h \ -../include/scheduler.h ../include/system.h \ -../include/iccp_consistency_check.h ../include/route_info.h \ -../include/iccp_netlink.h - -//CFLAGS = -g -O2 -fstack-protector-strong -Wformat -Werror=format-security $(LIBNL_CFLAGS) -I../include/ -CFLAGS = -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -I../include/ $(LIBNL_CFLAGS) -LDFLAGS = $(LIBNL_LIBS) -lpthread -LDADD = $(LIBZEBRA_BIN) - -all: iccpd - -%.o: %.c $(HEADERS) - -iccpd: $(OBJECTS) - $(CC) -o ../iccpd $(OBJECTS) $(LDFLAGS) - -DEPS = $(patsubst %.o, %.d, $(OBJECTS)) - --include $(DEPS) -%.d:%.c - @set -e; rm -f $@; \ - gcc -MM $(CPPFLAGS) $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ - - - -.PHONY: clean -clean: - -rm -f $(OBJECTS) $(DEPS) ../iccpd diff --git a/src/iccpd/src/Makefile.am b/src/iccpd/src/Makefile.am new file mode 100644 index 0000000000..9d19dbb528 --- /dev/null +++ b/src/iccpd/src/Makefile.am @@ -0,0 +1,22 @@ +SUBDIRS = mclagdctl + +INCLUDES = -I$(top_srcdir)/include -I/usr/include/libnl3 + +bin_PROGRAMS = iccpd + +if DEBUG +DBGFLAGS = -ggdb -DDEBUG +else +DBGFLAGS = -g -DNDEBUG +endif + +iccpd_SOURCES = \ + app_csm.c cmd_option.c iccp_cli.c iccp_cmd_show.c iccp_cmd.c \ + iccp_csm.c iccp_ifm.c iccp_main.c logger.c \ + port.c scheduler.c system.c iccp_consistency_check.c \ + mlacp_link_handler.c \ + mlacp_sync_prepare.c mlacp_sync_update.c\ + mlacp_fsm.c \ + iccp_netlink.c +iccpd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) +iccpd_LDADD = -lnl-genl-3 -lnl-route-3 -lnl-3 -lpthread diff --git a/src/iccpd/src/iccp_ifm.c b/src/iccpd/src/iccp_ifm.c index 5cfbfe81ff..ea8ce20f05 100644 --- a/src/iccpd/src/iccp_ifm.c +++ b/src/iccpd/src/iccp_ifm.c @@ -691,7 +691,7 @@ void do_arp_update_from_reply_packet(unsigned int ifindex, unsigned int addr, ui if (!verify_arp) return; - if (iccp_check_if_addr_from_netlink(AF_INET, &addr, arp_lif)) + if (iccp_check_if_addr_from_netlink(AF_INET, (uint8_t *)&addr, arp_lif)) { ICCPD_LOG_DEBUG(__FUNCTION__, "ARP %s is identical with the ip address of interface %s", show_ip_str(arp_msg->ipv4_addr), arp_lif->name); diff --git a/src/iccpd/src/mclagdctl/Makefile b/src/iccpd/src/mclagdctl/Makefile deleted file mode 100644 index 5520da22ce..0000000000 --- a/src/iccpd/src/mclagdctl/Makefile +++ /dev/null @@ -1,28 +0,0 @@ - - -C = gcc -SOURCES = \ -mclagdctl.c - -OBJECTS = \ -mclagdctl.o - -HEADERS = \ -mclagdctl.h - -CFLAGS = -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -LDFLAGS = -LDADD = - -all: mclagdctl - -%.o: %.c $(HEADERS) - -mclagdctl: $(OBJECTS) - $(CC) -o ./mclagdctl $(OBJECTS) $(LDFLAGS) - -.PHONY: clean -clean: - -rm -f $(OBJECTS) ./mclagdctl - - diff --git a/src/iccpd/src/mclagdctl/Makefile.am b/src/iccpd/src/mclagdctl/Makefile.am new file mode 100644 index 0000000000..124129c5d1 --- /dev/null +++ b/src/iccpd/src/mclagdctl/Makefile.am @@ -0,0 +1,10 @@ +bin_PROGRAMS = mclagdctl + +if DEBUG +DBGFLAGS = -ggdb -DDEBUG +else +DBGFLAGS = -g -DNDEBUG +endif + +mclagdctl_SOURCES = mclagdctl.c +mclagdctl_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) diff --git a/src/iccpd/src/mclagdctl/mclagdctl.c b/src/iccpd/src/mclagdctl/mclagdctl.c index 6e89772788..630e333be6 100644 --- a/src/iccpd/src/mclagdctl/mclagdctl.c +++ b/src/iccpd/src/mclagdctl/mclagdctl.c @@ -1,5 +1,5 @@ /* - /* Copyright(c) 2016-2019 Nephos. + * Copyright(c) 2016-2019 Nephos. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include #include diff --git a/src/iccpd/src/mlacp_sync_prepare.c b/src/iccpd/src/mlacp_sync_prepare.c index a278af5192..ef1cd244a9 100644 --- a/src/iccpd/src/mlacp_sync_prepare.c +++ b/src/iccpd/src/mlacp_sync_prepare.c @@ -370,7 +370,7 @@ int mlacp_prepare_for_arp_info(struct CSM* csm, char* buf, size_t max_buf_size, tlv->icc_parameter.type = htons(TLV_T_MLACP_ARP_INFO); } - ArpData = (struct mLACPMACData *)&buf[sizeof(ICCHdr) + sizeof(struct mLACPARPInfoTLV) + sizeof(struct ARPMsg) * count]; + ArpData = (struct ARPMsg *)&buf[sizeof(ICCHdr) + sizeof(struct mLACPARPInfoTLV) + sizeof(struct ARPMsg) * count]; ArpData->op_type = arp_msg->op_type; sprintf(ArpData->ifname, "%s", arp_msg->ifname); diff --git a/src/iccpd/src/port.c b/src/iccpd/src/port.c index ce23515a00..e63429a77c 100644 --- a/src/iccpd/src/port.c +++ b/src/iccpd/src/port.c @@ -28,6 +28,8 @@ #include "../include/port.h" #include "../include/system.h" #include "../include/iccp_csm.h" +#include "../include/iccp_netlink.h" +#include "../include/scheduler.h" void local_if_init(struct LocalInterface* local_if) { diff --git a/src/iccpd/src/scheduler.c b/src/iccpd/src/scheduler.c index c1a1532ccf..0ff9d4f5e0 100644 --- a/src/iccpd/src/scheduler.c +++ b/src/iccpd/src/scheduler.c @@ -731,7 +731,10 @@ int scheduler_unregister_sock_read_event_callback(struct CSM* csm) return MCLAG_ERROR; } - FD_CLR(csm->sock_fd, &(sys->readfd)); + if (csm->sock_fd > 0) + { + FD_CLR(csm->sock_fd, &(sys->readfd)); + } return 0; }