modernize backfire 10.03 so it can be operational again master
authoracoul <alex@ozo.com>
Tue, 19 Jul 2016 13:53:16 +0000 (16:53 +0300)
committeracoul <alex@ozo.com>
Tue, 19 Jul 2016 13:53:16 +0000 (16:53 +0300)
74 files changed:
include/depends.mk
include/package-ipkg.mk
include/package.mk
include/target.mk
package/bird/Makefile [new file with mode: 0644]
package/bird/files/bird4.conf [new file with mode: 0644]
package/bird/files/bird4.init [new file with mode: 0644]
package/bird/files/bird4loop [new file with mode: 0644]
package/bird/files/bird6.conf [new file with mode: 0644]
package/bird/files/bird6.init [new file with mode: 0644]
package/bird/files/bird6loop [new file with mode: 0644]
package/busybox/Makefile
package/busybox/config/Config.in
package/dnsmasq/Makefile
package/dnsmasq/patches/100-fix-dhcp-no-address-warning.patch [new file with mode: 0644]
package/dnsmasq/patches/101-ipv6.patch [deleted file]
package/dnsmasq/patches/110-ipset-remove-old-kernel-support.patch [new file with mode: 0644]
package/dnsmasq/patches/210-dnssec-improve-timestamp-heuristic.patch [new file with mode: 0644]
package/dnsmasq/patches/230-fix-poll-h-include-warning-on-musl.patch [new file with mode: 0644]
package/mtd/Makefile
package/mtd/src/Makefile
package/mtd/src/bcm_tag.h [new symlink]
package/mtd/src/fis.c
package/mtd/src/imagetag.c [new file with mode: 0644]
package/mtd/src/jffs2.c
package/mtd/src/md5.c [new file with mode: 0644]
package/mtd/src/md5.h [new file with mode: 0644]
package/mtd/src/mtd-api.h [deleted file]
package/mtd/src/mtd.c
package/mtd/src/mtd.h
package/mtd/src/seama.c [new file with mode: 0644]
package/mtd/src/seama.h [new file with mode: 0644]
package/mtd/src/trx.c
package/quagga/Makefile [new file with mode: 0644]
package/quagga/files/quagga [new file with mode: 0644]
package/quagga/files/quagga.conf [new file with mode: 0644]
package/quagga/files/quagga.init [new file with mode: 0644]
package/quagga/not-patches/patches-nopes/120-quagga_manet.patch [new file with mode: 0644]
package/quagga/not-patches/patches-nopes/158-next-hop-self_all.patch [new file with mode: 0644]
package/quagga/not-patches/patches-nopes/159-share_aspath.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/100-bgpd_Display_configured_dampening_parameters.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/110-bgpd_suppress_value_not_less_reuse_value.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/130-bgpd_ignore_stale_entry.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/140-bgpd-routes_from_established_peers.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/160-bgpd-enable_bgp_log-neighbor-changes.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/220-bgpd_dampening_command_tree.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/nopes/180-bgpd-lower_default_keepalive_holdtime.patch [new file with mode: 0644]
package/quagga/not-patches/patches-old/nopes/200-bgpd-implicit_updates_withdrawal_from_zebra.patch [new file with mode: 0644]
package/quagga/not-patches/patches-pgbgp/140-holdtimer-set.patch [new file with mode: 0644]
package/quagga/not-patches/patches-pgbgp/150-no-cross-fs-link.patch [new file with mode: 0644]
package/quagga/not-patches/patches-pgbgp/160-pgbgp.patch [new file with mode: 0644]
package/quagga/not-patches/patches-pgbgp/161-pgbgp-addon.patch [new file with mode: 0644]
package/quagga/not-patches/patches-pgbgp/162-bgp_table_wrapper.patch [new file with mode: 0644]
package/quagga/not-patches/patches-pgbgp/162-pgbgp-bgp_table_wrapper.patch [new file with mode: 0644]
package/quagga/not-patches/patches-pgbgp/170-use-supported-pagers.patch [new file with mode: 0644]
package/quagga/not-patches/patches-upstream/old/140-holdtimer-set.patch [new file with mode: 0644]
package/quagga/not-patches/patches-upstream/old/150-no-cross-fs-link.patch [new file with mode: 0644]
package/quagga/not-patches/patches-upstream/old/170-use-supported-pagers.patch [new file with mode: 0644]
package/quagga/patches-upstream/150-unknown_afi.patch [new file with mode: 0644]
package/quagga/patches-upstream/200-bgp_dampening.patch [new file with mode: 0644]
package/quagga/patches-upstream/210-dampening_commands.patch [new file with mode: 0644]
package/quagga/patches-upstream/300-fix_MRT.patch [new file with mode: 0644]
package/quagga/patches-upstream/320-fix_uninitialized_variables.patch [new file with mode: 0644]
package/quagga/patches-upstream/400-vpnv4_stat_fix.patch [new file with mode: 0644]
package/quagga/patches-upstream/999-old_uclibc.patch [new file with mode: 0644]
package/udevtrigger/patches/001-no_debug.patch
rules.mk
target/linux/atheros/Makefile
target/linux/atheros/config-2.6.30
target/linux/generic-2.6/patches-2.6.30/999-timeconst.patch [new file with mode: 0644]
toolchain/binutils/Makefile
toolchain/gcc/Makefile
toolchain/gcc/patches/4.4.1/999-gcc5.patch [new file with mode: 0644]
toolchain/gcc/patches/4.4.1/999-kill_inline.patch [new file with mode: 0644]

index 65e9b25d5e564499d4bf26d6ba871fbcffca39f5..828ceb8564e4c27458fc8eca78ccbc049b484617 100644 (file)
@@ -13,7 +13,7 @@
 
 DEP_FINDPARAMS := -x "*/.svn*" -x ".*" -x "*:*" -x "*\!*" -x "* *" -x "*\\\#*" -x "*/.*_check"
 
-find_md5=find $(1) -type f $(patsubst -x,-and -not -path,$(DEP_FINDPARAMS) $(2)) | md5s
+find_md5=$(SH_FUNC) find $(1) -type f $(patsubst -x,-and -not -path,$(DEP_FINDPARAMS) $(2)) | md5s
 
 define rdep
   .PRECIOUS: $(2)
index 0dd398e1baa35f1a1997981857bac833dab19b8c..5728b087566a058bd5cf7cca248c57f8d0ab7b6a 100644 (file)
@@ -30,7 +30,7 @@ IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
 define BuildIPKGVariable
 ifdef Package/$(1)/$(2)
   $(call shexport,Package/$(1)/$(2))
-  $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
+  $(1)_COMMANDS += $(SH_FUNC) var2file "$(call shvar,Package/$(1)/$(2))" $(2);
 endif
 endef
 
index 4c1d13864cd575fa9e89b3d494075d2c025825e7..9815aa85dd026f47f990e9924da941714953ead9 100644 (file)
@@ -131,7 +131,7 @@ define Build/DefaultTargets
                $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
        )
        if [ -d $(TMP_DIR)/stage-$(PKG_NAME) ]; then \
-               (cd $(TMP_DIR)/stage-$(PKG_NAME); find ./ > $(STAGING_DIR)/packages/$(STAGING_FILES_LIST)); \
+               (cd $(TMP_DIR)/stage-$(PKG_NAME); $(SH_FUNC) find ./ > $(STAGING_DIR)/packages/$(STAGING_FILES_LIST)); \
                $(CP) $(TMP_DIR)/stage-$(PKG_NAME)/* $(STAGING_DIR)/; \
        fi
        rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
index 0db3815939fe952149d0ca3fc177b2184c6f1954..f5e4609af35f556fbb1691c6e4d6401a3ba24599 100644 (file)
@@ -67,10 +67,10 @@ define Profile
                echo "Target-Profile-Kconfig: yes"; \
        fi; \
        echo "Target-Profile-Config: "; \
-       getvar "$(call shvar,Profile/$(1)/Config)"; \
+       $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Config)"; \
        echo "@@"; \
        echo "Target-Profile-Description:"; \
-       getvar "$(call shvar,Profile/$(1)/Description)"; \
+       $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Description)"; \
        echo "@@"; \
        echo;
   ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_)$(1))),y)
@@ -186,7 +186,7 @@ define BuildTargets/DumpCurrent
         echo 'Linux-Release: $(LINUX_RELEASE)'; \
         echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
         echo 'Target-Description:'; \
-        getvar $(call shvar,Target/Description); \
+        $(SH_FUNC) getvar $(call shvar,Target/Description); \
         echo '@@'; \
         echo 'Default-Packages: $(DEFAULT_PACKAGES)'; \
         $(DUMPINFO)
diff --git a/package/bird/Makefile b/package/bird/Makefile
new file mode 100644 (file)
index 0000000..68e85a2
--- /dev/null
@@ -0,0 +1,214 @@
+# 
+# Copyright (C) 2009-2015 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=bird
+PKG_VERSION:=1.6.0
+PKG_RELEASE:=1
+
+PKG_SOURCE:=bird-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=ftp://bird.network.cz/pub/bird
+PKG_MD5SUM:=4c92ec3548a2a120243879b6ef7046dd
+PKG_BUILD_DEPENDS:=libncurses libreadline
+PKG_MAINTAINER:=Álvaro Fernández Rojas <noltari@gmail.com>
+
+PKG_LICENSE:=GPL-2.0
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/bird/Default
+  TITLE:=The BIRD Internet Routing Daemon
+  URL:=http://bird.network.cz/
+  DEPENDS:=+libpthread
+endef
+
+define Package/birdc/Default
+  TITLE:=The BIRD command-line client
+  URL:=http://bird.network.cz/
+  DEPENDS:= +libreadline +libncurses
+endef
+
+define Package/birdcl/Default
+  TITLE:=The BIRD lightweight command-line client
+  URL:=http://bird.network.cz/
+endef
+
+define Package/bird/Default/description1
+BIRD is an internet routing daemon which manages TCP/IP routing tables
+with support of modern routing protocols, easy to use configuration
+interface and powerful route filtering language. It is lightweight and
+efficient and therefore appropriate for small embedded routers.
+
+endef
+
+define Package/bird/Default/description2
+In BGP, BIRD supports communities, multiprotocol extensions, MD5
+authentication, 32bit AS numbers and could act as a route server or a
+route reflector. BIRD also supports multiple RIBs, multiple kernel
+routing tables and redistribution between the protocols with a powerful
+configuration syntax.
+
+endef
+
+define Package/bird/Default/description3
+This is a BIRD command-line client. It is used to send commands to BIRD,
+commands can perform simple actions such as enabling/disabling of
+protocols, telling BIRD to show various information, telling it to show
+a routing table filtered by a filter, or asking BIRD to reconfigure.
+
+Unless you can't afford dependency on ncurses and readline, you
+should install BIRD command-line client together with BIRD.
+
+endef
+
+define Package/bird/Default/description4
+This is a BIRD lightweight command-line client. It is used to send commands to BIRD,
+commands can perform simple actions such as enabling/disabling of
+protocols, telling BIRD to show various information, telling it to show
+a routing table filtered by a filter, or asking BIRD to reconfigure.
+
+endef
+
+define Package/bird4
+$(call Package/bird/Default)
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Routing and Redirection
+  TITLE+= (IPv4)
+endef
+
+define Package/birdc4
+$(call Package/birdc/Default)
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Routing and Redirection
+  TITLE+= (IPv4)
+  DEPENDS+= +bird4
+endef
+
+define Package/birdcl4
+$(call Package/birdcl/Default)
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Routing and Redirection
+  TITLE+= (IPv4)
+  DEPENDS+= +bird4
+endef
+
+define Package/bird6
+$(call Package/bird/Default)
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Routing and Redirection
+  TITLE+= (IPv6)
+endef
+
+define Package/birdc6
+$(call Package/birdc/Default)
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Routing and Redirection
+  TITLE+= (IPv6)
+  DEPENDS+= +bird6
+endef
+
+define Package/birdcl6
+$(call Package/birdcl/Default)
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Routing and Redirection
+  TITLE+= (IPv6)
+  DEPENDS+= +bird6
+endef
+
+define Package/bird4/description
+$(call Package/bird/Default/description1)
+This is IPv4 version of BIRD, it supports OSPFv2, RIPv2 and BGP
+protocols.
+
+$(call Package/bird/Default/description2)
+endef
+
+define Package/birdc4/description
+$(call Package/bird/Default/description1)
+$(call Package/bird/Default/description3)
+endef
+
+define Package/birdcl4/description
+$(call Package/bird/Default/description1)
+$(call Package/bird/Default/description4)
+endef
+
+define Package/bird6/description
+$(call Package/bird/Default/description1)
+This is IPv6 version of BIRD, it supports OSPFv3, RIPng and BGP
+protocols.
+
+$(call Package/bird/Default/description2)
+endef
+
+define Package/birdc6/description
+$(call Package/bird/Default/description1)
+$(call Package/bird/Default/description3)
+endef
+
+define Package/birdcl6/description
+$(call Package/bird/Default/description1)
+$(call Package/bird/Default/description4)
+endef
+
+CONFIGURE_ARGS += --with-linux-headers="$(LINUX_DIR)"
+
+TARGET_CFLAGS+=-std=gnu89
+
+define Build/Template
+
+$(STAMP_BUILT)-$(2): $(STAMP_PREPARED)
+       $(call Build/Configure/Default,$(3))
+       $(call Build/Compile/Default,)
+       ( cd $(PKG_BUILD_DIR); mv -f bird bird$(2); mv -f birdc birdc$(2); mv -f birdcl birdcl$(2) )
+       -$(MAKE) -C $(PKG_BUILD_DIR) clean
+       touch $$@
+
+$(STAMP_BUILT): $(STAMP_BUILT)-$(2)
+
+define Package/bird$(2)/install
+       $(INSTALL_DIR)  $$(1)/usr/sbin
+       $(INSTALL_BIN)  $$(PKG_BUILD_DIR)/bird$(2) $$(1)/usr/sbin/
+       $(INSTALL_DIR)  $$(1)/etc
+       $(INSTALL_DATA) ./files/bird$(2).conf $$(1)/etc/
+       $(INSTALL_DIR)  $$(1)/etc/init.d
+       $(INSTALL_BIN)  ./files/bird$(2).init $$(1)/etc/init.d/bird$(2)
+
+endef
+
+define Package/bird$(2)/conffiles
+/etc/bird$(2).conf
+endef
+
+define Package/birdc$(2)/install
+       $(INSTALL_DIR) $$(1)/usr/sbin
+       $(INSTALL_BIN) $$(PKG_BUILD_DIR)/birdc$(2) $$(1)/usr/sbin/
+endef
+
+define Package/birdcl$(2)/install
+       $(INSTALL_DIR) $$(1)/usr/sbin
+       $(INSTALL_BIN) $$(PKG_BUILD_DIR)/birdcl$(2) $$(1)/usr/sbin/
+endef
+
+endef
+
+
+$(eval $(call Build/Template,bird4,4, --disable-ipv6))
+$(eval $(call Build/Template,bird6,6, --enable-ipv6))
+
+$(eval $(call BuildPackage,bird4))
+$(eval $(call BuildPackage,birdc4))
+$(eval $(call BuildPackage,birdcl4))
+$(eval $(call BuildPackage,bird6))
+$(eval $(call BuildPackage,birdc6))
+$(eval $(call BuildPackage,birdcl6))
diff --git a/package/bird/files/bird4.conf b/package/bird/files/bird4.conf
new file mode 100644 (file)
index 0000000..8616a0a
--- /dev/null
@@ -0,0 +1,121 @@
+
+# THIS CONFIG FILE IS NOT A COMPLETE DOCUMENTATION
+# PLEASE LOOK IN THE BIRD DOCUMENTATION FOR MORE INFO
+
+# However, most of options used here are just for example
+# and will be removed in real-life configs.
+
+log syslog all;
+
+# Override router ID
+#router id 192.168.0.1;
+
+# Turn on global debugging of all protocols
+#debug protocols all;
+
+
+# Define a route filter...
+# filter test_filter {
+#      if net ~ 10.0.0.0/16 then accept;
+#      else reject;
+# }
+
+# The direct protocol automatically generates device routes to all network
+# interfaces. Can exist in as many instances as you wish if you want to
+# populate multiple routing tables with device routes. Because device routes
+# are handled by Linux kernel, this protocol is  usually not needed.
+# protocol direct {
+#      interface "*";  # Restrict network interfaces it works with
+# }
+
+# This pseudo-protocol performs synchronization between BIRD's routing
+# tables and the kernel. You can run multiple instances of the kernel
+# protocol and synchronize different kernel tables with different BIRD tables.
+protocol kernel {
+#      learn;                  # Learn all alien routes from the kernel
+#      persist;                # Don't remove routes on bird shutdown
+       scan time 20;           # Scan kernel routing table every 20 seconds
+#      import none;            # Default is import all
+#      export all;             # Default is export none
+}
+
+# This pseudo-protocol watches all interface up/down events.
+protocol device {
+       scan time 10;           # Scan interfaces every 10 seconds
+}
+
+# Static routes (again, there can be multiple instances, so that you
+# can disable/enable various groups of static routes on the fly).
+protocol static {
+#      export all;             # Default is export none
+#      route 0.0.0.0/0 via 62.168.0.13;
+#      route 10.0.0.0/8 reject;
+#      route 192.168.0.0/16 reject;
+}
+
+
+#protocol rip {
+#      disabled;
+#      import all;
+#      export all;
+#      export filter test_filter;
+
+#      port 1520;
+#      period 7;
+#      infinity 16;
+#      garbage time 60;
+#      interface "*" { mode broadcast; };
+#      honor neighbor;
+#      honor always;
+#      honor never;
+#      authentication none;
+#}
+
+
+#protocol ospf {
+#      disabled;
+#      import all;
+#      export all;
+#      export where source = RTS_STATIC;
+
+#      area 0 {
+#              interface "eth*" {
+#                      cost 10;
+#                      hello 3;
+#                      retransmit 2;
+#                      wait 5;
+#                      dead 20;
+#                      type broadcast;
+#                      authentication simple;
+#                      password "pass";
+#              };
+#      };
+#}
+
+
+#protocol bgp {
+#      disabled;
+#      import all;
+#      export all;
+#      export where source = RTS_STATIC;
+
+#      local as 65000;
+#      neighbor 192.168.1.1 as 65001;
+#      multihop 20 via 192.168.2.1;
+
+#      hold time 240;
+#      startup hold time 240;
+#      connect retry time 120;
+#      keepalive time 80;      # defaults to hold time / 3
+#      start delay time 5;     # How long do we wait before initial connect
+#      error wait time 60, 300;# Minimum and maximum time we wait after an error (when consecutive
+#                              # errors occur, we increase the delay exponentially ...
+#      error forget time 300;  # ... until this timeout expires)
+#      disable after error;    # Disable the protocol automatically when an error occurs
+#      next hop self;          # Disable next hop processing and always advertise our local address as nexthop
+#      source address 62.168.0.14;     # What local address we use for the TCP connection
+#      password "secret"       # Password used for MD5 authentication
+#      rr client;              # I am a route reflector and the neighor is my client
+#      rr cluster id 1.0.0.1   # Use this value for cluster id instead of my router id 
+#      };
+#}
diff --git a/package/bird/files/bird4.init b/package/bird/files/bird4.init
new file mode 100644 (file)
index 0000000..8ac5e75
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2010-2011 OpenWrt.org
+
+START=50
+
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+
+start() {
+       service_start /usr/sbin/bird4 -d
+#      ( SERVICE_MATCH_NAME=1 service_start /usr/sbin/bird4loop )
+}
+
+stop() {
+#      ( SERVICE_MATCH_NAME=1 service_stop /usr/sbin/bird4loop )
+       service_stop /usr/sbin/bird4
+}
+
+reload() {
+       service_reload /usr/sbin/bird4
+}
diff --git a/package/bird/files/bird4loop b/package/bird/files/bird4loop
new file mode 100644 (file)
index 0000000..074a9a2
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+BIRD=/usr/sbin/bird4
+
+$BIRD -p || return 1
+
+. /lib/functions.sh
+. /lib/functions/service.sh
+
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+
+sig_handler() {
+       running=0
+       service_stop $BIRD
+}
+
+running=1
+trap sig_handler INT
+trap sig_handler TERM
+while [ $running -gt 0 ]; do
+       service_check $BIRD || service_start $BIRD -d "$@"
+       sleep 3
+done
diff --git a/package/bird/files/bird6.conf b/package/bird/files/bird6.conf
new file mode 100644 (file)
index 0000000..8616a0a
--- /dev/null
@@ -0,0 +1,121 @@
+
+# THIS CONFIG FILE IS NOT A COMPLETE DOCUMENTATION
+# PLEASE LOOK IN THE BIRD DOCUMENTATION FOR MORE INFO
+
+# However, most of options used here are just for example
+# and will be removed in real-life configs.
+
+log syslog all;
+
+# Override router ID
+#router id 192.168.0.1;
+
+# Turn on global debugging of all protocols
+#debug protocols all;
+
+
+# Define a route filter...
+# filter test_filter {
+#      if net ~ 10.0.0.0/16 then accept;
+#      else reject;
+# }
+
+# The direct protocol automatically generates device routes to all network
+# interfaces. Can exist in as many instances as you wish if you want to
+# populate multiple routing tables with device routes. Because device routes
+# are handled by Linux kernel, this protocol is  usually not needed.
+# protocol direct {
+#      interface "*";  # Restrict network interfaces it works with
+# }
+
+# This pseudo-protocol performs synchronization between BIRD's routing
+# tables and the kernel. You can run multiple instances of the kernel
+# protocol and synchronize different kernel tables with different BIRD tables.
+protocol kernel {
+#      learn;                  # Learn all alien routes from the kernel
+#      persist;                # Don't remove routes on bird shutdown
+       scan time 20;           # Scan kernel routing table every 20 seconds
+#      import none;            # Default is import all
+#      export all;             # Default is export none
+}
+
+# This pseudo-protocol watches all interface up/down events.
+protocol device {
+       scan time 10;           # Scan interfaces every 10 seconds
+}
+
+# Static routes (again, there can be multiple instances, so that you
+# can disable/enable various groups of static routes on the fly).
+protocol static {
+#      export all;             # Default is export none
+#      route 0.0.0.0/0 via 62.168.0.13;
+#      route 10.0.0.0/8 reject;
+#      route 192.168.0.0/16 reject;
+}
+
+
+#protocol rip {
+#      disabled;
+#      import all;
+#      export all;
+#      export filter test_filter;
+
+#      port 1520;
+#      period 7;
+#      infinity 16;
+#      garbage time 60;
+#      interface "*" { mode broadcast; };
+#      honor neighbor;
+#      honor always;
+#      honor never;
+#      authentication none;
+#}
+
+
+#protocol ospf {
+#      disabled;
+#      import all;
+#      export all;
+#      export where source = RTS_STATIC;
+
+#      area 0 {
+#              interface "eth*" {
+#                      cost 10;
+#                      hello 3;
+#                      retransmit 2;
+#                      wait 5;
+#                      dead 20;
+#                      type broadcast;
+#                      authentication simple;
+#                      password "pass";
+#              };
+#      };
+#}
+
+
+#protocol bgp {
+#      disabled;
+#      import all;
+#      export all;
+#      export where source = RTS_STATIC;
+
+#      local as 65000;
+#      neighbor 192.168.1.1 as 65001;
+#      multihop 20 via 192.168.2.1;
+
+#      hold time 240;
+#      startup hold time 240;
+#      connect retry time 120;
+#      keepalive time 80;      # defaults to hold time / 3
+#      start delay time 5;     # How long do we wait before initial connect
+#      error wait time 60, 300;# Minimum and maximum time we wait after an error (when consecutive
+#                              # errors occur, we increase the delay exponentially ...
+#      error forget time 300;  # ... until this timeout expires)
+#      disable after error;    # Disable the protocol automatically when an error occurs
+#      next hop self;          # Disable next hop processing and always advertise our local address as nexthop
+#      source address 62.168.0.14;     # What local address we use for the TCP connection
+#      password "secret"       # Password used for MD5 authentication
+#      rr client;              # I am a route reflector and the neighor is my client
+#      rr cluster id 1.0.0.1   # Use this value for cluster id instead of my router id 
+#      };
+#}
diff --git a/package/bird/files/bird6.init b/package/bird/files/bird6.init
new file mode 100644 (file)
index 0000000..2efb4f0
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2010-2011 OpenWrt.org
+
+START=50
+
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+
+start() {
+       service_start /usr/sbin/bird6 -d
+#      ( SERVICE_MATCH_NAME=1 service_start /usr/sbin/bird6loop )
+}
+
+stop() {
+#      ( SERVICE_MATCH_NAME=1 service_stop /usr/sbin/bird6loop )
+       service_stop /usr/sbin/bird6
+}
+
+reload() {
+       service_reload /usr/sbin/bird6
+}
diff --git a/package/bird/files/bird6loop b/package/bird/files/bird6loop
new file mode 100644 (file)
index 0000000..c01cf2e
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+BIRD=/usr/sbin/bird6
+
+$BIRD -p || return 1
+
+. /lib/functions.sh
+. /lib/functions/service.sh
+
+SERVICE_DAEMONIZE=1
+SERVICE_WRITE_PID=1
+
+sig_handler() {
+       running=0
+       service_stop $BIRD
+}
+
+running=1
+trap sig_handler INT
+trap sig_handler TERM
+while [ $running -gt 0 ]; do
+       service_check $BIRD || service_start $BIRD -d "$@"
+       sleep 3
+done
index ac41b6412303dc7049acea910417ed590473b56f..06d6341a861f3adfa849d57ef5e0eda1f0e7c028 100644 (file)
@@ -20,7 +20,7 @@ PKG_MD5SUM:=6059ac9456de6fb18dc8ee4cd0ec9240
 include $(INCLUDE_DIR)/package.mk
 
 ifeq ($(DUMP),)
-  STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell grep '^CONFIG_BUSYBOX_' $(TOPDIR)/.config | md5s)
+  STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell $(SH_FUNC) grep '^CONFIG_BUSYBOX_' $(TOPDIR)/.config | md5s)
 endif
 
 init-y :=
index 3beb0d12a063ac9e83ef890e7d229578195386a0..acf71c953bd5ff3786d1ccc2428bc60247911223 100644 (file)
@@ -397,7 +397,7 @@ config BUSYBOX_CONFIG_FEATURE_SHARED_BUSYBOX
 
 config BUSYBOX_CONFIG_LFS
        bool
-       default y
+       default n
        select BUSYBOX_CONFIG_FDISK_SUPPORT_LARGE_DISKS
        help
          If you want to build BusyBox with large file support, then enable
index 19eb663340143af8cee3594d8c8d7451777de655..05872ec0d6968c05665c192d229299d6eb956afe 100644 (file)
@@ -8,15 +8,27 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=dnsmasq
-PKG_VERSION:=2.55
-PKG_RELEASE:=6.1
+PKG_VERSION:=2.76
+PKG_RELEASE:=3
 
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq
-PKG_MD5SUM:=b093d7c6bc7f97ae6fd35d048529232a
+PKG_MD5SUM:=00f5ee66b4e4b7f14538bf62ae3c9461
 
 include $(INCLUDE_DIR)/package.mk
 
+TARGET_CFLAGS += -ffunction-sections -fdata-sections
+TARGET_LDFLAGS += -Wl,--gc-sections
+
+COPTS = -DNO_IPV6 -DNO_DHCP6 -DNO_AUTH -DNO_IPSET -DNO_LARGEFILE -DNO_INOTIFY
+
+MAKE_FLAGS := \
+       $(TARGET_CONFIGURE_OPTS) \
+       CFLAGS="$(TARGET_CFLAGS)" \
+       LDFLAGS="$(TARGET_LDFLAGS)" \
+       COPTS="$(COPTS)" \
+       PREFIX="/usr"
+
 define Package/dnsmasq
   SECTION:=net
   CATEGORY:=Base system
@@ -35,6 +47,7 @@ endef
 
 define Build/Compile
        $(MAKE) -C $(PKG_BUILD_DIR) \
+               $(MAKE_FLAGS) \
                $(TARGET_CONFIGURE_OPTS) \
                CFLAGS="$(TARGET_CFLAGS)" \
                BINDIR="/usr/sbin" MANDIR="/usr/man" \
diff --git a/package/dnsmasq/patches/100-fix-dhcp-no-address-warning.patch b/package/dnsmasq/patches/100-fix-dhcp-no-address-warning.patch
new file mode 100644 (file)
index 0000000..5fc62ff
--- /dev/null
@@ -0,0 +1,47 @@
+--- a/src/dhcp.c
++++ b/src/dhcp.c
+@@ -147,7 +147,7 @@ void dhcp_packet(time_t now, int pxe_fd)
+   ssize_t sz; 
+   int iface_index = 0, unicast_dest = 0, is_inform = 0;
+   int rcvd_iface_index;
+-  struct in_addr iface_addr;
++  struct in_addr iface_addr, *addrp = NULL;
+   struct iface_param parm;
+ #ifdef HAVE_LINUX_NETWORK
+   struct arpreq arp_req;
+@@ -277,11 +277,9 @@ void dhcp_packet(time_t now, int pxe_fd)
+     {
+       ifr.ifr_addr.sa_family = AF_INET;
+       if (ioctl(daemon->dhcpfd, SIOCGIFADDR, &ifr) != -1 )
+-      iface_addr = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr;
+-      else
+       {
+-        my_syslog(MS_DHCP | LOG_WARNING, _("DHCP packet received on %s which has no address"), ifr.ifr_name);
+-        return;
++        addrp = &iface_addr;
++        iface_addr = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr;
+       }
+       
+       for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
+@@ -300,7 +298,7 @@ void dhcp_packet(time_t now, int pxe_fd)
+       parm.relay_local.s_addr = 0;
+       parm.ind = iface_index;
+       
+-      if (!iface_check(AF_INET, (struct all_addr *)&iface_addr, ifr.ifr_name, NULL))
++      if (!iface_check(AF_INET, (struct all_addr *)addrp, ifr.ifr_name, NULL))
+       {
+         /* If we failed to match the primary address of the interface, see if we've got a --listen-address
+            for a secondary */
+@@ -320,6 +318,12 @@ void dhcp_packet(time_t now, int pxe_fd)
+         complete_context(match.addr, iface_index, NULL, match.netmask, match.broadcast, &parm);
+       }    
+       
++      if (!addrp)
++        {
++          my_syslog(MS_DHCP | LOG_WARNING, _("DHCP packet received on %s which has no address"), ifr.ifr_name);
++          return;
++        }
++
+       if (!iface_enumerate(AF_INET, &parm, complete_context))
+       return;
diff --git a/package/dnsmasq/patches/101-ipv6.patch b/package/dnsmasq/patches/101-ipv6.patch
deleted file mode 100644 (file)
index 2876d3e..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
---- a/src/config.h
-+++ b/src/config.h
-@@ -269,8 +269,9 @@ NOTES:
- /* We assume that systems which don't have IPv6
-    headers don't have ntop and pton either */
--#if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY) && !defined(NO_IPV6)
-+#if defined(INET6_ADDRSTRLEN) && !defined(NO_IPV6)
- #  define HAVE_IPV6
-+#  define IPV6_V6ONLY 26
- #  define ADDRSTRLEN INET6_ADDRSTRLEN
- #  if defined(SOL_IPV6)
- #    define IPV6_LEVEL SOL_IPV6
diff --git a/package/dnsmasq/patches/110-ipset-remove-old-kernel-support.patch b/package/dnsmasq/patches/110-ipset-remove-old-kernel-support.patch
new file mode 100644 (file)
index 0000000..61b09d5
--- /dev/null
@@ -0,0 +1,110 @@
+--- a/src/ipset.c
++++ b/src/ipset.c
+@@ -22,7 +22,6 @@
+ #include <errno.h>
+ #include <sys/types.h>
+ #include <sys/socket.h>
+-#include <sys/utsname.h>
+ #include <arpa/inet.h>
+ #include <linux/version.h>
+ #include <linux/netlink.h>
+@@ -72,7 +71,7 @@ struct my_nfgenmsg {
+ #define NL_ALIGN(len) (((len)+3) & ~(3))
+ static const struct sockaddr_nl snl = { .nl_family = AF_NETLINK };
+-static int ipset_sock, old_kernel;
++static int ipset_sock;
+ static char *buffer;
+ static inline void add_attr(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data)
+@@ -87,25 +86,7 @@ static inline void add_attr(struct nlmsg
+ void ipset_init(void)
+ {
+-  struct utsname utsname;
+-  int version;
+-  char *split;
+-  
+-  if (uname(&utsname) < 0)
+-    die(_("failed to find kernel version: %s"), NULL, EC_MISC);
+-  
+-  split = strtok(utsname.release, ".");
+-  version = (split ? atoi(split) : 0);
+-  split = strtok(NULL, ".");
+-  version = version * 256 + (split ? atoi(split) : 0);
+-  split = strtok(NULL, ".");
+-  version = version * 256 + (split ? atoi(split) : 0);
+-  old_kernel = (version < KERNEL_VERSION(2,6,32));
+-  
+-  if (old_kernel && (ipset_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) != -1)
+-    return;
+-  
+-  if (!old_kernel && 
++  if ( 
+       (buffer = safe_malloc(BUFF_SZ)) &&
+       (ipset_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER)) != -1 &&
+       (bind(ipset_sock, (struct sockaddr *)&snl, sizeof(snl)) != -1))
+@@ -168,62 +149,16 @@ static int new_add_to_ipset(const char *
+ }
+-static int old_add_to_ipset(const char *setname, const struct all_addr *ipaddr, int remove)
+-{
+-  socklen_t size;
+-  struct ip_set_req_adt_get {
+-    unsigned op;
+-    unsigned version;
+-    union {
+-      char name[IPSET_MAXNAMELEN];
+-      uint16_t index;
+-    } set;
+-    char typename[IPSET_MAXNAMELEN];
+-  } req_adt_get;
+-  struct ip_set_req_adt {
+-    unsigned op;
+-    uint16_t index;
+-    uint32_t ip;
+-  } req_adt;
+-  
+-  if (strlen(setname) >= sizeof(req_adt_get.set.name)) 
+-    {
+-      errno = ENAMETOOLONG;
+-      return -1;
+-    }
+-  
+-  req_adt_get.op = 0x10;
+-  req_adt_get.version = 3;
+-  strcpy(req_adt_get.set.name, setname);
+-  size = sizeof(req_adt_get);
+-  if (getsockopt(ipset_sock, SOL_IP, 83, &req_adt_get, &size) < 0)
+-    return -1;
+-  req_adt.op = remove ? 0x102 : 0x101;
+-  req_adt.index = req_adt_get.set.index;
+-  req_adt.ip = ntohl(ipaddr->addr.addr4.s_addr);
+-  if (setsockopt(ipset_sock, SOL_IP, 83, &req_adt, sizeof(req_adt)) < 0)
+-    return -1;
+-  
+-  return 0;
+-}
+-
+-
+-
+ int add_to_ipset(const char *setname, const struct all_addr *ipaddr, int flags, int remove)
+ {
+   int af = AF_INET;
+ #ifdef HAVE_IPV6
+   if (flags & F_IPV6)
+-    {
+       af = AF_INET6;
+-      /* old method only supports IPv4 */
+-      if (old_kernel)
+-      return -1;
+-    }
+ #endif
+   
+-  return old_kernel ? old_add_to_ipset(setname, ipaddr, remove) : new_add_to_ipset(setname, ipaddr, af, remove);
++  return new_add_to_ipset(setname, ipaddr, af, remove);
+ }
+ #endif
diff --git a/package/dnsmasq/patches/210-dnssec-improve-timestamp-heuristic.patch b/package/dnsmasq/patches/210-dnssec-improve-timestamp-heuristic.patch
new file mode 100644 (file)
index 0000000..ca5a806
--- /dev/null
@@ -0,0 +1,47 @@
+From 79e60e145f8a595bca5a784c00b437216d51de68 Mon Sep 17 00:00:00 2001
+From: Steven Barth <steven@midlink.org>
+Date: Mon, 13 Apr 2015 09:45:20 +0200
+Subject: [PATCH] dnssec: improve timestamp heuristic
+
+Signed-off-by: Steven Barth <steven@midlink.org>
+---
+ src/dnssec.c | 15 +++++++++++----
+ 1 file changed, 11 insertions(+), 4 deletions(-)
+
+--- a/src/dnssec.c
++++ b/src/dnssec.c
+@@ -462,17 +462,24 @@ static time_t timestamp_time;
+ int setup_timestamp(void)
+ {
+   struct stat statbuf;
++  time_t now;
++  time_t base = 1420070400; /* 1-1-2015 */
+   
+   daemon->back_to_the_future = 0;
+   
+   if (!daemon->timestamp_file)
+     return 0;
++
++  now = time(NULL);
++
++  if (!stat("/proc/self/exe", &statbuf) && difftime(statbuf.st_mtime, base) > 0)
++    base = statbuf.st_mtime;
+   
+   if (stat(daemon->timestamp_file, &statbuf) != -1)
+     {
+       timestamp_time = statbuf.st_mtime;
+     check_and_exit:
+-      if (difftime(timestamp_time, time(0)) <=  0)
++      if (difftime(now, base) >= 0 && difftime(timestamp_time, now) <= 0)
+       {
+         /* time already OK, update timestamp, and do key checking from the start. */
+         if (utime(daemon->timestamp_file, NULL) == -1)
+@@ -493,7 +500,7 @@ int setup_timestamp(void)
+         close(fd);
+         
+-        timestamp_time = timbuf.actime = timbuf.modtime = 1420070400; /* 1-1-2015 */
++        timestamp_time = timbuf.actime = timbuf.modtime = base;
+         if (utime(daemon->timestamp_file, &timbuf) == 0)
+           goto check_and_exit;
+       }
diff --git a/package/dnsmasq/patches/230-fix-poll-h-include-warning-on-musl.patch b/package/dnsmasq/patches/230-fix-poll-h-include-warning-on-musl.patch
new file mode 100644 (file)
index 0000000..19300f7
--- /dev/null
@@ -0,0 +1,18 @@
+dnsmasq: fix warning with poll.h include on musl
+
+Warning is:
+  #warning redirecting incorrect #include <sys/poll.h> to <poll.h>
+
+Signed-off-by: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
+
+--- a/src/dnsmasq.h
++++ b/src/dnsmasq.h
+@@ -82,7 +82,7 @@ typedef unsigned long long u64;
+ #if defined(HAVE_SOLARIS_NETWORK)
+ #  include <sys/sockio.h>
+ #endif
+-#include <sys/poll.h>
++#include <poll.h>
+ #include <sys/wait.h>
+ #include <sys/time.h>
+ #include <sys/un.h>
index 332ce3034cd8e35356afc43b8a58fb248d184dd6..1eb3b4a51e96ee738b59d69621723a72f1448fcd 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006-2009 OpenWrt.org
+# Copyright (C) 2006-2012 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=mtd
-PKG_RELEASE:=13
+PKG_RELEASE:=18.1
 
 PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
 STAMP_PREPARED := $(STAMP_PREPARED)_$(call confvar,CONFIG_MTD_REDBOOT_PARTS)
@@ -23,7 +23,7 @@ define Package/mtd
 endef
 
 define Package/mtd/description
- This package contains an utility useful to upgrade from other firmware or 
+ This package contains an utility useful to upgrade from other firmware or
  older OpenWrt releases.
 endef
 
@@ -35,7 +35,7 @@ endef
 target=$(firstword $(subst -, ,$(BOARD)))
 
 MAKE_FLAGS += TARGET="$(target)"
-TARGET_CFLAGS += -Dtarget_$(target)=1 -Wall
+TARGET_CFLAGS := -I$(LINUX_DIR)/include $(TARGET_CFLAGS) -Dtarget_$(target)=1 -Wall
 
 ifdef CONFIG_MTD_REDBOOT_PARTS
   MAKE_FLAGS += FIS_SUPPORT=1
index bb509be8ba261a8edf0d6662cd421e7eaf98baf1..4e6aee8eb5fa47d27dad28b5bfa0283719e4c9a6 100644 (file)
@@ -2,8 +2,12 @@ CC = gcc
 CFLAGS += -Wall
 
 obj = mtd.o jffs2.o crc32.o
+obj.seama = seama.o md5.o
+obj.ar71xx = trx.o
 obj.brcm = trx.o
 obj.brcm47xx = $(obj.brcm)
+obj.brcm63xx = imagetag.o
+obj.ramips = $(obj.seama)
 
 ifdef FIS_SUPPORT
   obj += fis.o
@@ -11,4 +15,4 @@ endif
 
 mtd: $(obj) $(obj.$(TARGET))
 clean:
-       rm -f *.o jffs2 
+       rm -f *.o jffs2
diff --git a/package/mtd/src/bcm_tag.h b/package/mtd/src/bcm_tag.h
new file mode 120000 (symlink)
index 0000000..2e977a2
--- /dev/null
@@ -0,0 +1 @@
+../../../target/linux/brcm63xx/files/arch/mips/include/asm/mach-bcm63xx/bcm_tag.h
\ No newline at end of file
index 559ca95069a510cd6f76e66ca0d5cfafe3cb4a6f..f825f590c96a50141849d24c63b9d652ab146808 100644 (file)
@@ -143,6 +143,8 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
        struct fis_image_desc *redboot = NULL;
        struct fis_image_desc *first = NULL;
        struct fis_image_desc *last = NULL;
+       struct fis_image_desc *first_fb = NULL;
+       struct fis_image_desc *last_fb = NULL;
        struct fis_image_desc *desc;
        struct fis_part *part;
        uint32_t offset = 0, size = 0;
@@ -184,13 +186,21 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
        }
        desc--;
 
+       first_fb = first;
+       last_fb = last;
+
+       if (first_fb->hdr.flash_base > last_fb->hdr.flash_base) {
+               first_fb = last;
+               last_fb = first;
+       }
+
        /* determine size of available space */
        desc = (struct fis_image_desc *) start;
        while ((char *) desc < end) {
                if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff))
                        break;
 
-               if (desc->hdr.flash_base > last->hdr.flash_base &&
+               if (desc->hdr.flash_base > last_fb->hdr.flash_base &&
                    desc->hdr.flash_base < offset)
                        offset = desc->hdr.flash_base;
 
@@ -198,7 +208,7 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
        }
        desc--;
 
-       size = offset - first->hdr.flash_base;
+       size = offset - first_fb->hdr.flash_base;
 
 #ifdef notyet
        desc = first - 1;
@@ -214,7 +224,7 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new)
 
        last++;
        desc = first + n_new;
-       offset = first->hdr.flash_base;
+       offset = first_fb->hdr.flash_base;
 
        if (desc != last) {
                if (desc > last)
diff --git a/package/mtd/src/imagetag.c b/package/mtd/src/imagetag.c
new file mode 100644 (file)
index 0000000..a4ce86d
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ * imagetag.c
+ *
+ * Copyright (C) 2005 Mike Baker
+ * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ * Copyrigth (C) 2010 Daniel Dickinson <openwrt@cshore.neomailbox.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <errno.h>
+
+#include <sys/ioctl.h>
+#include <mtd/mtd-user.h>
+#include "mtd.h"
+#include "crc32.h"
+#include "bcm_tag.h"
+
+ssize_t pread(int fd, void *buf, size_t count, off_t offset);
+ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
+
+#define CRC_START 0xFFFFFFFF
+
+static uint32_t strntoul(char *str, char **endptr, int base, size_t len) {
+  char *newstr;
+  uint32_t res = 0;
+
+  newstr = calloc(len + 1, sizeof(char));
+  if (newstr) {
+       strncpy(newstr, str, len); 
+       res = strtoul(newstr, endptr, base);
+       free(newstr);
+  }
+  return res;
+}
+
+uint32_t compute_crc32(uint32_t crc, off_t start, size_t compute_len, int fd)
+{
+       uint8_t readbuf[1024];
+       ssize_t res;
+       off_t offset = start;
+
+       /* Read a buffer's worth of bytes  */
+       while (fd && (compute_len >= sizeof(readbuf))) {
+               res = pread(fd, readbuf, sizeof(readbuf), offset);
+               crc = crc32(crc, readbuf, res);
+               compute_len = compute_len - res;
+               offset += res;
+       }
+
+       /* Less than buffer-size bytes remains, read compute_len bytes */
+       if (fd && (compute_len > 0)) {
+         res = pread(fd, readbuf, compute_len, offset);
+         crc = crc32(crc, readbuf, res);
+       }
+
+       return crc;
+}
+
+int
+trx_fixup(int fd, const char *name)
+{
+       struct mtd_info_user mtdInfo;
+       unsigned long len;
+       void *ptr, *scan;
+       int bfd;
+       struct bcm_tag *tag;
+       ssize_t res;
+       uint32_t cfelen, imagelen, imagestart, rootfslen;
+       uint32_t imagecrc, rootfscrc, headercrc;
+       uint32_t offset = 0;
+       cfelen = imagelen = imagestart = imagecrc = rootfscrc = headercrc = rootfslen = 0;
+
+
+       if (ioctl(fd, MEMGETINFO, &mtdInfo) < 0) {
+               fprintf(stderr, "Failed to get mtd info\n");
+               goto err;
+       }
+
+       len = mtdInfo.size;
+       if (mtdInfo.size <= 0) {
+               fprintf(stderr, "Invalid MTD device size\n");
+               goto err;
+       }
+
+       bfd = mtd_open(name, true);
+       ptr = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, bfd, 0);
+       if (!ptr || (ptr == (void *) -1)) {
+               perror("mmap");
+               goto err1;
+       }
+
+       tag = (struct bcm_tag *) (ptr);
+
+       cfelen = strntoul(&tag->cfeLength[0], NULL, 10, IMAGE_LEN);
+       if (cfelen) {
+         fprintf(stderr, "Non-zero CFE length.  This is currently unsupported.\n");
+         exit(1);
+       }
+
+       headercrc = compute_crc32(CRC_START, offset, offsetof(struct bcm_tag, headerCRC), fd);
+       if (headercrc != *(uint32_t *)(&tag->headerCRC[0])) {
+               fprintf(stderr, "Tag verify failed.  This may not be a valid image.\n");
+               exit(1);
+       }
+
+       sprintf(&tag->flashRootLength[0], "%lu", 0);
+       strncpy(&tag->totalLength[0], &tag->kernelLength[0], IMAGE_LEN);
+
+       imagestart = sizeof(tag);
+       memcpy(&tag->imageCRC[0], &tag->kernelCRC[0], CRC_LEN);
+       memcpy(&tag->fskernelCRC[0], &tag->kernelCRC[0], CRC_LEN);
+       rootfscrc = CRC_START;
+       memcpy(&tag->rootfsCRC[0], &rootfscrc, sizeof(uint32_t));
+       headercrc = crc32(CRC_START, tag, offsetof(struct bcm_tag, headerCRC));
+       memcpy(&tag->headerCRC[0], &headercrc, sizeof(uint32_t));
+
+       msync(ptr, sizeof(struct bcm_tag), MS_SYNC|MS_INVALIDATE);
+       munmap(ptr, len);
+       close(bfd);
+       return 0;
+
+err1:
+       close(bfd);
+err:
+       fprintf(stderr, "Error fixing up imagetag header\n");
+       return -1;
+}
+
+
+int
+trx_check(int imagefd, const char *mtd, char *buf, int *len)
+{
+    struct bcm_tag *tag = (const struct bcm_tag *) buf;
+       int fd;
+       uint32_t headerCRC;
+       uint32_t imageLen;
+
+       if (strcmp(mtd, "linux") != 0)
+               return 1;
+
+       *len = read(imagefd, buf, sizeof(struct bcm_tag));
+       if (*len < sizeof(struct bcm_tag)) {
+               fprintf(stdout, "Could not get image header, file too small (%d bytes)\n", *len);
+               return 0;
+       }
+       headerCRC = crc32buf(buf, offsetof(struct bcm_tag, headerCRC));
+       if (*(uint32_t *)(&tag->headerCRC[0]) != headerCRC) {
+  
+         if (quiet < 2) {
+               fprintf(stderr, "Bad header CRC got %08lx, calculated %08lx\n",
+                               *(uint32_t *)(&tag->headerCRC[0]), headerCRC);
+               fprintf(stderr, "This is not the correct file format; refusing to flash.\n"
+                               "Please specify the correct file or use -f to force.\n");
+         }
+         return 0;
+       }
+
+       /* check if image fits to mtd device */
+       fd = mtd_check_open(mtd);
+       if(fd < 0) {
+               fprintf(stderr, "Could not open mtd device: %s\n", mtd);
+               exit(1);
+       }
+
+       imageLen = strntoul(&tag->totalLength[0], NULL, 10, IMAGE_LEN);
+       
+       if(mtdsize < imageLen) {
+               fprintf(stderr, "Image too big for partition: %s\n", mtd);
+               close(fd);
+               return 0;
+       }
+
+       close(fd);
+       return 1;
+}
+
+int
+mtd_fixtrx(const char *mtd, size_t offset)
+{
+       int fd;
+       struct bcm_tag *tag;
+       char *buf;
+       ssize_t res;
+       size_t block_offset;
+       uint32_t cfelen, imagelen, imagestart, rootfslen;
+       uint32_t imagecrc, rootfscrc, headercrc;
+       cfelen = imagelen = imagestart = imagecrc = rootfscrc = headercrc = rootfslen = 0;
+
+       if (quiet < 2)
+               fprintf(stderr, "Trying to fix trx header in %s at 0x%x...\n", mtd, offset);
+
+       block_offset = offset & ~(erasesize - 1);
+       offset -= block_offset;
+
+       fd = mtd_check_open(mtd);
+       if(fd < 0) {
+               fprintf(stderr, "Could not open mtd device: %s\n", mtd);
+               exit(1);
+       }
+
+       if (block_offset + erasesize > mtdsize) {
+               fprintf(stderr, "Offset too large, device size 0x%x\n", mtdsize);
+               exit(1);
+       }
+
+       buf = malloc(erasesize);
+       if (!buf) {
+               perror("malloc");
+               exit(1);
+       }
+
+       res = pread(fd, buf, erasesize, block_offset);
+       if (res != erasesize) {
+               perror("pread");
+               exit(1);
+       }
+
+       tag = (struct bcm_tag *) (buf + offset);
+
+       cfelen = strntoul(&tag->cfeLength[0], NULL, 10, IMAGE_LEN);
+       if (cfelen) {
+         fprintf(stderr, "Non-zero CFE length.  This is currently unsupported.\n");
+         exit(1);
+       }
+
+       if (quiet < 2) {
+         fprintf(stderr, "Verifying we actually have an imagetag.\n");
+       }
+
+       headercrc = compute_crc32(CRC_START, offset, offsetof(struct bcm_tag, headerCRC), fd);
+       if (headercrc != *(uint32_t *)(&tag->headerCRC[0])) {
+               fprintf(stderr, "Tag verify failed.  This may not be a valid image.\n");
+               exit(1);
+       }
+
+       if (quiet < 2) {
+         fprintf(stderr, "Checking current fixed status.\n");
+       }
+
+       rootfslen = strntoul(&tag->flashRootLength[0], NULL, 10, IMAGE_LEN);
+       if (rootfslen == 0) {
+         if (quiet < 2) 
+               fprintf(stderr, "Header already fixed, exiting\n");
+         close(fd);
+         return 0;
+       }
+
+       if (quiet < 2) {
+         fprintf(stderr, "Setting root length to 0.\n");
+       }
+
+       sprintf(&tag->flashRootLength[0], "%lu", 0);
+       strncpy(&tag->totalLength[0], &tag->kernelLength[0], IMAGE_LEN);
+
+       if (quiet < 2) {
+         fprintf(stderr, "Recalculating CRCs.\n");
+       }
+
+       imagestart = sizeof(tag);
+       memcpy(&tag->imageCRC[0], &tag->kernelCRC[0], CRC_LEN);
+       memcpy(&tag->fskernelCRC[0], &tag->kernelCRC[0], CRC_LEN);
+       rootfscrc = CRC_START;
+       memcpy(&tag->rootfsCRC[0], &rootfscrc, sizeof(uint32_t));
+       headercrc = crc32(CRC_START, tag, offsetof(struct bcm_tag, headerCRC));
+       memcpy(&tag->headerCRC[0], &headercrc, sizeof(uint32_t));
+
+       if (quiet < 2) {
+         fprintf(stderr, "Erasing imagetag block\n");
+       }
+
+       if (mtd_erase_block(fd, block_offset)) {
+               fprintf(stderr, "Can't erase block at 0x%x (%s)\n", block_offset, strerror(errno));
+               exit(1);
+       }
+
+       if (quiet < 2) {
+         fprintf(stderr, "New image crc32: 0x%x, rewriting block\n", 
+                         *(uint32_t *)(&tag->imageCRC[0]));
+         fprintf(stderr, "New header crc32: 0x%x, rewriting block\n", headercrc);  
+       }
+
+       if (pwrite(fd, buf, erasesize, block_offset) != erasesize) {
+               fprintf(stderr, "Error writing block (%s)\n", strerror(errno));
+               exit(1);
+       }
+
+       if (quiet < 2)
+               fprintf(stderr, "Done.\n");
+
+       close (fd);
+       sync();
+       return 0;
+
+}
index 49a7d56120e05cc78a6e12754a1a67c9eab2670a..2a83bd47f4aa2ba5422cffae1d37991758468f5e 100644 (file)
@@ -244,10 +244,7 @@ int mtd_replace_jffs2(const char *mtd, int fd, int ofs, const char *filename)
        pad(erasesize);
        free(buf);
 
-#ifdef target_brcm
-       trx_fixup(outfd, mtd);
-#endif
-       return 0;
+       return (mtdofs - ofs);
 }
 
 void mtd_parse_jffs2data(const char *buf, const char *dir)
@@ -347,9 +344,9 @@ int mtd_write_jffs2(const char *mtd, const char *filename, const char *dir)
 
        err = 0;
 
-#ifdef target_brcm
-       trx_fixup(outfd, mtd);
-#endif
+       if (trx_fixup) {
+         trx_fixup(outfd, mtd);
+       }
 
 done:
        close(outfd);
diff --git a/package/mtd/src/md5.c b/package/mtd/src/md5.c
new file mode 100644 (file)
index 0000000..2039760
--- /dev/null
@@ -0,0 +1,307 @@
+
+
+/*
+ ***********************************************************************
+ ** md5.c -- the source code for MD5 routines                         **
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **
+ ** Created: 2/17/90 RLR                                              **
+ ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
+ **                                                                   **
+ ** License to copy and use this software is granted provided that    **
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
+ ** Digest Algorithm" in all material mentioning or referencing this  **
+ ** software or this function.                                        **
+ **                                                                   **
+ ** License is also granted to make and use derivative works          **
+ ** provided that such works are identified as "derived from the RSA  **
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
+ ** material mentioning or referencing the derived work.              **
+ **                                                                   **
+ ** RSA Data Security, Inc. makes no representations concerning       **
+ ** either the merchantability of this software or the suitability    **
+ ** of this software for any particular purpose.  It is provided "as  **
+ ** is" without express or implied warranty of any kind.              **
+ **                                                                   **
+ ** These notices must be retained in any copies of any part of this  **
+ ** documentation and/or software.                                    **
+ ***********************************************************************
+ */
+
+#include <string.h>
+#include "md5.h"
+
+/*
+ ***********************************************************************
+ **  Message-digest routines:                                         **
+ **  To form the message digest for a message M                       **
+ **    (1) Initialize a context buffer mdContext using MD5_Init       **
+ **    (2) Call MD5_Update on mdContext and M                         **
+ **    (3) Call MD5_Final on mdContext                                **
+ **  The message digest is now in mdContext->digest[0...15]           **
+ ***********************************************************************
+ */
+
+/* forward declaration */
+static void Transform ();
+
+static unsigned char PADDING[64] = {
+  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/* F, G, H and I are basic MD5 functions */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
+/* Rotation is separate from addition to prevent recomputation */
+#define FF(a, b, c, d, x, s, ac) \
+  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+#define GG(a, b, c, d, x, s, ac) \
+  {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+#define HH(a, b, c, d, x, s, ac) \
+  {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+#define II(a, b, c, d, x, s, ac) \
+  {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+
+#ifdef __STDC__
+#define UL(x)  x##U
+#else
+#define UL(x)  x
+#endif
+
+/* The routine MD5_Init initializes the message-digest context
+   mdContext. All fields are set to zero.
+ */
+void MD5_Init (mdContext)
+MD5_CTX *mdContext;
+{
+  mdContext->i[0] = mdContext->i[1] = (UINT4)0;
+
+  /* Load magic initialization constants.
+   */
+  mdContext->buf[0] = (UINT4)0x67452301;
+  mdContext->buf[1] = (UINT4)0xefcdab89;
+  mdContext->buf[2] = (UINT4)0x98badcfe;
+  mdContext->buf[3] = (UINT4)0x10325476;
+}
+
+/* The routine MD5Update updates the message-digest context to
+   account for the presence of each of the characters inBuf[0..inLen-1]
+   in the message whose digest is being computed.
+ */
+void MD5_Update (mdContext, inBuf, inLen)
+MD5_CTX *mdContext;
+unsigned char *inBuf;
+unsigned int inLen;
+{
+  UINT4 in[16];
+  int mdi;
+  unsigned int i, ii;
+
+  /* compute number of bytes mod 64 */
+  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
+
+  /* update number of bits */
+  if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
+    mdContext->i[1]++;
+  mdContext->i[0] += ((UINT4)inLen << 3);
+  mdContext->i[1] += ((UINT4)inLen >> 29);
+
+  while (inLen--) {
+    /* add new character to buffer, increment mdi */
+    mdContext->in[mdi++] = *inBuf++;
+
+    /* transform if necessary */
+    if (mdi == 0x40) {
+      for (i = 0, ii = 0; i < 16; i++, ii += 4)
+        in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+                (((UINT4)mdContext->in[ii+2]) << 16) |
+                (((UINT4)mdContext->in[ii+1]) << 8) |
+                ((UINT4)mdContext->in[ii]);
+      Transform (mdContext->buf, in);
+      mdi = 0;
+    }
+  }
+}
+
+/* The routine MD5Final terminates the message-digest computation and
+   ends with the desired message digest in mdContext->digest[0...15].
+ */
+void MD5_Final (hash, mdContext)
+unsigned char hash[];
+MD5_CTX *mdContext;
+{
+  UINT4 in[16];
+  int mdi;
+  unsigned int i, ii;
+  unsigned int padLen;
+
+  /* save number of bits */
+  in[14] = mdContext->i[0];
+  in[15] = mdContext->i[1];
+
+  /* compute number of bytes mod 64 */
+  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
+
+  /* pad out to 56 mod 64 */
+  padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
+  MD5_Update (mdContext, PADDING, padLen);
+
+  /* append length in bits and transform */
+  for (i = 0, ii = 0; i < 14; i++, ii += 4)
+    in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+            (((UINT4)mdContext->in[ii+2]) << 16) |
+            (((UINT4)mdContext->in[ii+1]) << 8) |
+            ((UINT4)mdContext->in[ii]);
+  Transform (mdContext->buf, in);
+
+  /* store buffer in digest */
+  for (i = 0, ii = 0; i < 4; i++, ii += 4) {
+    mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
+    mdContext->digest[ii+1] =
+      (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
+    mdContext->digest[ii+2] =
+      (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
+    mdContext->digest[ii+3] =
+      (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
+  }
+  memcpy(hash, mdContext->digest, 16);
+}
+
+/* Basic MD5 step. Transforms buf based on in.
+ */
+static void Transform (buf, in)
+UINT4 *buf;
+UINT4 *in;
+{
+  UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
+
+  /* Round 1 */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+  FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
+  FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
+  FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
+  FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
+  FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
+  FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
+  FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
+  FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
+  FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
+  FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
+  FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
+  FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
+  FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
+  FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
+  FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
+  FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
+
+  /* Round 2 */
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+  GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
+  GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
+  GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
+  GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
+  GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
+  GG ( d, a, b, c, in[10], S22, UL(  38016083)); /* 22 */
+  GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
+  GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
+  GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
+  GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
+  GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
+  GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
+  GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
+  GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
+  GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
+  GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
+
+  /* Round 3 */
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+  HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
+  HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
+  HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
+  HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
+  HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
+  HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
+  HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
+  HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
+  HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
+  HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
+  HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
+  HH ( b, c, d, a, in[ 6], S34, UL(  76029189)); /* 44 */
+  HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
+  HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
+  HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
+  HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
+
+  /* Round 4 */
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+  II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
+  II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
+  II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
+  II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
+  II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
+  II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
+  II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
+  II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
+  II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
+  II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
+  II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
+  II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
+  II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
+  II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
+  II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
+  II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
+
+  buf[0] += a;
+  buf[1] += b;
+  buf[2] += c;
+  buf[3] += d;
+}
+
+/*
+ ***********************************************************************
+ ** End of md5.c                                                      **
+ ******************************** (cut) ********************************
+ */
diff --git a/package/mtd/src/md5.h b/package/mtd/src/md5.h
new file mode 100644 (file)
index 0000000..f7a0c96
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ ***********************************************************************
+ ** md5.h -- header file for implementation of MD5                    **
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **
+ ** Created: 2/17/90 RLR                                              **
+ ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version               **
+ ** Revised (for MD5): RLR 4/27/91                                    **
+ **   -- G modified to have y&~z instead of y&z                       **
+ **   -- FF, GG, HH modified to add in last register done             **
+ **   -- Access pattern: round 2 works mod 5, round 3 works mod 3     **
+ **   -- distinct additive constant for each step                     **
+ **   -- round 4 added, working mod 7                                 **
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
+ **                                                                   **
+ ** License to copy and use this software is granted provided that    **
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
+ ** Digest Algorithm" in all material mentioning or referencing this  **
+ ** software or this function.                                        **
+ **                                                                   **
+ ** License is also granted to make and use derivative works          **
+ ** provided that such works are identified as "derived from the RSA  **
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
+ ** material mentioning or referencing the derived work.              **
+ **                                                                   **
+ ** RSA Data Security, Inc. makes no representations concerning       **
+ ** either the merchantability of this software or the suitability    **
+ ** of this software for any particular purpose.  It is provided "as  **
+ ** is" without express or implied warranty of any kind.              **
+ **                                                                   **
+ ** These notices must be retained in any copies of any part of this  **
+ ** documentation and/or software.                                    **
+ ***********************************************************************
+ */
+
+#ifndef __MD5_INCLUDE__
+
+/* typedef a 32-bit type */
+#ifdef _LP64
+typedef unsigned int UINT4;
+typedef int          INT4;
+#else
+typedef unsigned long UINT4;
+typedef long          INT4;
+#endif
+#define _UINT4_T
+
+/* Data structure for MD5 (Message-Digest) computation */
+typedef struct {
+  UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */
+  UINT4 buf[4];                                    /* scratch buffer */
+  unsigned char in[64];                              /* input buffer */
+  unsigned char digest[16];     /* actual digest after MD5Final call */
+} MD5_CTX;
+
+void MD5_Init ();
+void MD5_Update ();
+void MD5_Final ();
+
+#define __MD5_INCLUDE__
+#endif /* __MD5_INCLUDE__ */
diff --git a/package/mtd/src/mtd-api.h b/package/mtd/src/mtd-api.h
deleted file mode 100644 (file)
index 272043d..0000000
+++ /dev/null
@@ -1,304 +0,0 @@
-
-
-#ifndef __MTD_MTD_H__
-#define __MTD_MTD_H__
-
-#ifdef __KERNEL__
-
-#include <linux/config.h>
-#include <linux/version.h>
-#include <linux/types.h>
-#include <linux/mtd/compatmac.h>
-#include <linux/notifier.h>
-#include <linux/module.h>
-#include <linux/uio.h>
-
-#endif /* __KERNEL__ */
-
-struct erase_info_user {
-       u_int32_t start;
-       u_int32_t length;
-};
-
-struct mtd_oob_buf {
-       u_int32_t start;
-       u_int32_t length;
-       unsigned char *ptr;
-};
-
-
-#define MTD_CHAR_MAJOR 90
-#define MTD_BLOCK_MAJOR 31
-#define MAX_MTD_DEVICES 16
-
-
-
-#define MTD_ABSENT             0
-#define MTD_RAM                        1
-#define MTD_ROM                        2
-#define MTD_NORFLASH           3
-#define MTD_NANDFLASH          4
-#define MTD_PEROM              5
-#define MTD_OTHER              14
-#define MTD_UNKNOWN            15
-
-
-
-#define MTD_CLEAR_BITS         1       // Bits can be cleared (flash)
-#define MTD_SET_BITS           2       // Bits can be set
-#define MTD_ERASEABLE          4       // Has an erase function
-#define MTD_WRITEB_WRITEABLE   8       // Direct IO is possible
-#define MTD_VOLATILE           16      // Set for RAMs
-#define MTD_XIP                        32      // eXecute-In-Place possible
-#define MTD_OOB                        64      // Out-of-band data (NAND flash)
-#define MTD_ECC                        128     // Device capable of automatic ECC
-
-// Some common devices / combinations of capabilities
-#define MTD_CAP_ROM            0
-#define MTD_CAP_RAM            (MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEB_WRITEABLE)
-#define MTD_CAP_NORFLASH        (MTD_CLEAR_BITS|MTD_ERASEABLE)
-#define MTD_CAP_NANDFLASH       (MTD_CLEAR_BITS|MTD_ERASEABLE|MTD_OOB)
-#define MTD_WRITEABLE          (MTD_CLEAR_BITS|MTD_SET_BITS)
-
-
-// Types of automatic ECC/Checksum available
-#define MTD_ECC_NONE           0       // No automatic ECC available
-#define MTD_ECC_RS_DiskOnChip  1       // Automatic ECC on DiskOnChip
-#define MTD_ECC_SW             2       // SW ECC for Toshiba & Samsung devices
-
-struct mtd_info_user {
-       u_char type;
-       u_int32_t flags;
-       u_int32_t size;  // Total size of the MTD
-       u_int32_t erasesize;
-       u_int32_t oobblock;  // Size of OOB blocks (e.g. 512)
-       u_int32_t oobsize;   // Amount of OOB data per block (e.g. 16)
-       u_int32_t ecctype;
-       u_int32_t eccsize;
-};
-
-struct region_info_user {
-       u_int32_t offset;               /* At which this region starts, 
-                                        * from the beginning of the MTD */
-       u_int32_t erasesize;            /* For this region */
-       u_int32_t numblocks;            /* Number of blocks in this region */
-       u_int32_t regionindex;
-};
-
-#define MEMGETINFO              _IOR('M', 1, struct mtd_info_user)
-#define MEMERASE                _IOW('M', 2, struct erase_info_user)
-#define MEMWRITEOOB             _IOWR('M', 3, struct mtd_oob_buf)
-#define MEMREADOOB              _IOWR('M', 4, struct mtd_oob_buf)
-#define MEMLOCK                 _IOW('M', 5, struct erase_info_user)
-#define MEMUNLOCK               _IOW('M', 6, struct erase_info_user)
-#define MEMGETREGIONCOUNT      _IOR('M', 7, int)
-#define MEMGETREGIONINFO       _IOWR('M', 8, struct region_info_user)
-#define        MEMREADDATA             _IOWR('M', 9, struct mtd_oob_buf)
-#define        MEMWRITEDATA            _IOWR('M', 10, struct mtd_oob_buf)
-#define MTDREFRESH                             _IO('M', 23)
-
-#ifndef __KERNEL__
-
-typedef struct mtd_info_user mtd_info_t;
-typedef struct erase_info_user erase_info_t;
-typedef struct region_info_user region_info_t;
-
-       /* User-space ioctl definitions */
-
-
-#else /* __KERNEL__ */
-
-
-#define MTD_ERASE_PENDING              0x01
-#define MTD_ERASING            0x02
-#define MTD_ERASE_SUSPEND      0x04
-#define MTD_ERASE_DONE          0x08
-#define MTD_ERASE_FAILED        0x10
-
-struct erase_info {
-       struct mtd_info *mtd;
-       u_int32_t addr;
-       u_int32_t len;
-       u_long time;
-       u_long retries;
-       u_int dev;
-       u_int cell;
-       void (*callback) (struct erase_info *self);
-       u_long priv;
-       u_char state;
-       struct erase_info *next;
-};
-
-struct mtd_erase_region_info {
-       u_int32_t offset;                       /* At which this region starts, from the beginning of the MTD */
-       u_int32_t erasesize;            /* For this region */
-       u_int32_t numblocks;            /* Number of blocks of erasesize in this region */
-};
-
-struct mtd_info {
-       u_char type;
-       u_int32_t flags;
-       u_int32_t size;  // Total size of the MTD
-
-       /* "Major" erase size for the device. Naïve users may take this
-        * to be the only erase size available, or may use the more detailed
-        * information below if they desire
-        */
-       u_int32_t erasesize;
-
-       u_int32_t oobblock;  // Size of OOB blocks (e.g. 512)
-       u_int32_t oobsize;   // Amount of OOB data per block (e.g. 16)
-       u_int32_t ecctype;
-       u_int32_t eccsize;
-
-       // Kernel-only stuff starts here.
-       char *name;
-       int index;
-
-       /* Data for variable erase regions. If numeraseregions is zero,
-        * it means that the whole device has erasesize as given above. 
-        */
-       int numeraseregions;
-       struct mtd_erase_region_info *eraseregions; 
-
-       /* This really shouldn't be here. It can go away in 2.5 */
-       u_int32_t bank_size;
-
-       struct module *module;
-       int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
-
-       /* This stuff for eXecute-In-Place */
-       int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
-
-       /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
-       void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len);
-
-
-       int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
-       int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
-
-       int (*read_ecc) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf, int oobsel);
-       int (*write_ecc) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf, u_char *eccbuf, int oobsel);
-
-       int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
-       int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
-
-       /* 
-        * Methods to access the protection register area, present in some 
-        * flash devices. The user data is one time programmable but the
-        * factory data is read only. 
-        */
-       int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
-
-       int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
-
-       /* This function is not yet implemented */
-       int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
-
-       /* iovec-based read/write methods. We need these especially for NAND flash,
-          with its limited number of write cycles per erase.
-          NB: The 'count' parameter is the number of _vectors_, each of 
-          which contains an (ofs, len) tuple.
-       */
-       int (*readv) (struct mtd_info *mtd, struct iovec *vecs, unsigned long count, loff_t from, size_t *retlen);
-       int (*readv_ecc) (struct mtd_info *mtd, struct iovec *vecs, unsigned long count, loff_t from, 
-               size_t *retlen, u_char *eccbuf, int oobsel);
-       int (*writev) (struct mtd_info *mtd, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen);
-       int (*writev_ecc) (struct mtd_info *mtd, const struct iovec *vecs, unsigned long count, loff_t to, 
-               size_t *retlen, u_char *eccbuf, int oobsel);
-
-       /* Sync */
-       void (*sync) (struct mtd_info *mtd);
-
-       /* Chip-supported device locking */
-       int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
-       int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
-
-       /* Power Management functions */
-       int (*suspend) (struct mtd_info *mtd);
-       void (*resume) (struct mtd_info *mtd);
-
-       struct notifier_block reboot_notifier;
-
-       void *priv;
-};
-
-
-       /* Kernel-side ioctl definitions */
-
-extern int add_mtd_device(struct mtd_info *mtd);
-extern int del_mtd_device (struct mtd_info *mtd);
-
-extern struct mtd_info *__get_mtd_device(struct mtd_info *mtd, int num);
-
-static inline struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
-{
-       struct mtd_info *ret;
-       
-       ret = __get_mtd_device(mtd, num);
-
-       if (ret && ret->module && !try_inc_mod_count(ret->module))
-               return NULL;
-
-       return ret;
-}
-
-static inline void put_mtd_device(struct mtd_info *mtd)
-{
-       if (mtd->module)
-              __MOD_DEC_USE_COUNT(mtd->module);
-}
-
-
-struct mtd_notifier {
-       void (*add)(struct mtd_info *mtd);
-       void (*remove)(struct mtd_info *mtd);
-       struct mtd_notifier *next;
-};
-
-
-extern void register_mtd_user (struct mtd_notifier *new);
-extern int unregister_mtd_user (struct mtd_notifier *old);
-
-int default_mtd_writev(struct mtd_info *mtd, const struct iovec *vecs,
-                      unsigned long count, loff_t to, size_t *retlen);
-
-int default_mtd_readv(struct mtd_info *mtd, struct iovec *vecs,
-                     unsigned long count, loff_t from, size_t *retlen);
-
-#ifndef MTDC
-#define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
-#define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
-#define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
-#define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
-#define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
-#define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
-#define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
-#define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
-#define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
-#define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
-#define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
-#define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd);  } while (0) 
-#endif /* MTDC */
-
-/*
- * Debugging macro and defines
- */
-#define MTD_DEBUG_LEVEL0       (0)     /* Quiet   */
-#define MTD_DEBUG_LEVEL1       (1)     /* Audible */
-#define MTD_DEBUG_LEVEL2       (2)     /* Loud    */
-#define MTD_DEBUG_LEVEL3       (3)     /* Noisy   */
-
-#ifdef CONFIG_MTD_DEBUG
-#define DEBUG(n, args...)                              \
-       do {                                            \
-               if (n <= CONFIG_MTD_DEBUG_VERBOSE)      \
-                       printk(KERN_INFO args);         \
-       } while(0)
-#else /* CONFIG_MTD_DEBUG */
-#define DEBUG(n, args...)
-#endif /* CONFIG_MTD_DEBUG */
-
-#endif /* __KERNEL__ */
-
-#endif /* __MTD_MTD_H__ */
index ff75fcb8a93435ff02a1d407c01dab8fdc213e81..9a6e65d0de1219c671a286491a58a82d311c2d24 100644 (file)
 #include <sys/stat.h>
 #include <sys/reboot.h>
 #include <linux/reboot.h>
-#include "mtd-api.h"
+#include <mtd/mtd-user.h>
 #include "fis.h"
 #include "mtd.h"
-#include "crc32.h"
 
-#define MAX_ARGS 8
-#define JFFS2_DEFAULT_DIR      "" /* directory name without /, empty means root dir */
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define STORE32_LE(X)           ((((X) & 0x000000FF) << 24) | (((X) & 0x0000FF00) << 8) | (((X) & 0x00FF0000) >> 8) | (((X) & 0xFF000000) >> 24))
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-#define STORE32_LE(X)           (X)
-#else
-#error unkown endianness!
+#ifndef MTDREFRESH
+#define MTDREFRESH     _IO('M', 50)
 #endif
 
-ssize_t pread(int fd, void *buf, size_t count, off_t offset);
-ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
-
-#define TRX_MAGIC       0x30524448      /* "HDR0" */
-struct trx_header {
-       uint32_t magic;         /* "HDR0" */
-       uint32_t len;           /* Length of file including header */
-       uint32_t crc32;         /* 32-bit CRC from flag_version to end of file */
-       uint32_t flag_version;  /* 0:15 flags, 16:31 version */
-       uint32_t offsets[3];    /* Offsets of partitions from start of header */
-};
+#define MAX_ARGS 8
+#define JFFS2_DEFAULT_DIR      "" /* directory name without /, empty means root dir */
 
 static char *buf = NULL;
 static char *imagefile = NULL;
 static char *jffs2file = NULL, *jffs2dir = JFFS2_DEFAULT_DIR;
 static int buflen = 0;
 int quiet;
+int no_erase;
 int mtdsize = 0;
 int erasesize = 0;
 
@@ -150,9 +134,10 @@ static int
 image_check(int imagefd, const char *mtd)
 {
        int ret = 1;
-#ifdef target_brcm
-       ret = trx_check(imagefd, mtd, buf, &buflen);
-#endif
+       if (trx_check) {
+         ret = trx_check(imagefd, mtd, buf, &buflen);
+       }
+
        return ret;
 }
 
@@ -264,82 +249,6 @@ mtd_erase(const char *mtd)
 
 }
 
-static int
-mtd_fixtrx(const char *mtd, size_t offset)
-{
-       int fd;
-       struct trx_header *trx;
-       char *buf;
-       ssize_t res;
-       size_t block_offset;
-
-       if (quiet < 2)
-               fprintf(stderr, "Trying to fix trx header in %s at 0x%x...\n", mtd, offset);
-
-       block_offset = offset & ~(erasesize - 1);
-       offset -= block_offset;
-
-       fd = mtd_check_open(mtd);
-       if(fd < 0) {
-               fprintf(stderr, "Could not open mtd device: %s\n", mtd);
-               exit(1);
-       }
-
-       if (block_offset + erasesize > mtdsize) {
-               fprintf(stderr, "Offset too large, device size 0x%x\n", mtdsize);
-               exit(1);
-       }
-
-       buf = malloc(erasesize);
-       if (!buf) {
-               perror("malloc");
-               exit(1);
-       }
-
-       res = pread(fd, buf, erasesize, block_offset);
-       if (res != erasesize) {
-               perror("pread");
-               exit(1);
-       }
-
-       trx = (struct trx_header *) (buf + offset);
-       if (trx->magic != STORE32_LE(0x30524448)) {
-               fprintf(stderr, "No trx magic found\n");
-               exit(1);
-       }
-
-       if (trx->len == STORE32_LE(erasesize - offset)) {
-               if (quiet < 2)
-                       fprintf(stderr, "Header already fixed, exiting\n");
-               close(fd);
-               return 0;
-       }
-
-       trx->len = STORE32_LE(erasesize - offset);
-
-       trx->crc32 = STORE32_LE(crc32buf((char*) &trx->flag_version, erasesize - offset - 3*4));
-       if (mtd_erase_block(fd, block_offset)) {
-               fprintf(stderr, "Can't erease block at 0x%x (%s)\n", block_offset, strerror(errno));
-               exit(1);
-       }
-
-       if (quiet < 2)
-               fprintf(stderr, "New crc32: 0x%x, rewriting block\n", trx->crc32);
-
-       if (pwrite(fd, buf, erasesize, block_offset) != erasesize) {
-               fprintf(stderr, "Error writing block (%s)\n", strerror(errno));
-               exit(1);
-       }
-
-       if (quiet < 2)
-               fprintf(stderr, "Done.\n");
-
-       close (fd);
-       sync();
-       return 0;
-
-}
-
 static int
 mtd_refresh(const char *mtd)
 {
@@ -367,14 +276,26 @@ mtd_refresh(const char *mtd)
        return 0;
 }
 
+static void
+indicate_writing(const char *mtd)
+{
+       if (quiet < 2)
+               fprintf(stderr, "\nWriting from %s to %s ... ", imagefile, mtd);
+
+       if (!quiet)
+               fprintf(stderr, " [ ]");
+}
+
 static int
-mtd_write(int imagefd, const char *mtd, char *fis_layout)
+mtd_write(int imagefd, const char *mtd, char *fis_layout, size_t part_offset)
 {
        char *next = NULL;
        char *str = NULL;
        int fd, result;
        ssize_t r, w, e;
+       ssize_t skip = 0;
        uint32_t offset = 0;
+       int jffs2_replaced = 0;
 
 #ifdef FIS_SUPPORT
        static struct fis_part new_parts[MAX_ARGS];
@@ -451,13 +372,14 @@ resume:
                exit(1);
        }
 
-       if (quiet < 2)
-               fprintf(stderr, "Writing from %s to %s ... ", imagefile, mtd);
+       if (part_offset > 0) {
+               fprintf(stderr, "Seeking on mtd device '%s' to: %u\n", mtd, part_offset);
+               lseek(fd, part_offset, SEEK_SET);
+       }
 
-       w = e = 0;
-       if (!quiet)
-               fprintf(stderr, " [ ]");
+       indicate_writing(mtd);
 
+       w = e = 0;
        for (;;) {
                /* buffer may contain data already (from trx check or last mtd partition write attempt) */
                while (buflen < erasesize) {
@@ -480,6 +402,15 @@ resume:
                if (buflen == 0)
                        break;
 
+               if (skip > 0) {
+                       skip -= buflen;
+                       buflen = 0;
+                       if (skip <= 0)
+                               indicate_writing(mtd);
+
+                       continue;
+               }
+
                if (jffs2file) {
                        if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF) - 1) == 0) {
                                if (!quiet)
@@ -487,8 +418,18 @@ resume:
                                if (quiet < 2)
                                        fprintf(stderr, "\nAppending jffs2 data from %s to %s...", jffs2file, mtd);
                                /* got an EOF marker - this is the place to add some jffs2 data */
-                               mtd_replace_jffs2(mtd, fd, e, jffs2file);
-                               goto done;
+                               skip = mtd_replace_jffs2(mtd, fd, e, jffs2file);
+                               jffs2_replaced = 1;
+
+                               /* don't add it again */
+                               jffs2file = NULL;
+
+                               w += skip;
+                               e += skip;
+                               skip -= buflen;
+                               buflen = 0;
+                               offset = 0;
+                               continue;
                        }
                        /* no EOF marker, make sure we figure out the last inode number
                         * before appending some data */
@@ -496,31 +437,34 @@ resume:
                }
 
                /* need to erase the next block before writing data to it */
-               while (w + buflen > e) {
-                       if (!quiet)
-                               fprintf(stderr, "\b\b\b[e]");
-
-
-                       if (mtd_erase_block(fd, e) < 0) {
-                               if (next) {
-                                       if (w < e) {
-                                               write(fd, buf + offset, e - w);
-                                               offset = e - w;
+               if(!no_erase)
+               {
+                       while (w + buflen > e) {
+                               if (!quiet)
+                                       fprintf(stderr, "\b\b\b[e]");
+
+
+                               if (mtd_erase_block(fd, e) < 0) {
+                                       if (next) {
+                                               if (w < e) {
+                                                       write(fd, buf + offset, e - w);
+                                                       offset = e - w;
+                                               }
+                                               w = 0;
+                                               e = 0;
+                                               close(fd);
+                                               mtd = next;
+                                               fprintf(stderr, "\b\b\b   \n");
+                                               goto resume;
+                                       } else {
+                                               fprintf(stderr, "Failed to erase block\n");
+                                               exit(1);
                                        }
-                                       w = 0;
-                                       e = 0;
-                                       close(fd);
-                                       mtd = next;
-                                       fprintf(stderr, "\b\b\b   \n");
-                                       goto resume;
-                               } else {
-                                       fprintf(stderr, "Failed to erase block\n");
-                                       exit(1);
                                }
-                       }
 
-                       /* erase the chunk */
-                       e += erasesize;
+                               /* erase the chunk */
+                               e += erasesize;
+                       }
                }
 
                if (!quiet)
@@ -541,6 +485,10 @@ resume:
                offset = 0;
        }
 
+       if (jffs2_replaced && trx_fixup) {
+               trx_fixup(fd, mtd);
+       }
+
        if (!quiet)
                fprintf(stderr, "\b\b\b\b    ");
 
@@ -568,17 +516,31 @@ static void usage(void)
        "        refresh                 refresh mtd partition\n"
        "        erase                   erase all data on device\n"
        "        write <imagefile>|-     write <imagefile> (use - for stdin) to device\n"
-       "        jffs2write <file>       append <file> to the jffs2 partition on the device\n"
-       "        fixtrx                  fix the checksum in a trx header on first boot\n"
+       "        jffs2write <file>       append <file> to the jffs2 partition on the device\n");
+       if (mtd_fixtrx) {
+           fprintf(stderr,
+       "        fixtrx                  fix the checksum in a trx header on first boot\n");
+       }
+       if (mtd_fixseama) {
+           fprintf(stderr,
+       "        fixseama                fix the checksum in a seama header on first boot\n");
+       }
+    fprintf(stderr,
        "Following options are available:\n"
        "        -q                      quiet mode (once: no [w] on writing,\n"
        "                                           twice: no status messages)\n"
+       "        -n                      write without first erasing the blocks\n"
        "        -r                      reboot after successful command\n"
        "        -f                      force write without trx checks\n"
        "        -e <device>             erase <device> before executing the command\n"
        "        -d <name>               directory for jffs2write, defaults to \"tmp\"\n"
        "        -j <name>               integrate <file> into jffs2 data when writing an image\n"
-       "        -o offset               offset of the trx header in the partition (for fixtrx)\n"
+       "        -p                      write beginning at partition offset\n");
+       if (mtd_fixtrx) {
+           fprintf(stderr,
+       "        -o offset               offset of the image header in the partition(for fixtrx)\n");
+    }
+       fprintf(stderr,
 #ifdef FIS_SUPPORT
        "        -F <part>[:<size>[:<entrypoint>]][,<part>...]\n"
        "                                alter the fis partition table to create new partitions replacing\n"
@@ -609,7 +571,7 @@ int main (int argc, char **argv)
        int ch, i, boot, imagefd = 0, force, unlocked;
        char *erase[MAX_ARGS], *device = NULL;
        char *fis_layout = NULL;
-       size_t offset = 0;
+       size_t offset = 0, part_offset = 0;
        enum {
                CMD_ERASE,
                CMD_WRITE,
@@ -617,6 +579,7 @@ int main (int argc, char **argv)
                CMD_REFRESH,
                CMD_JFFS2WRITE,
                CMD_FIXTRX,
+               CMD_FIXSEAMA,
        } cmd = -1;
 
        erase[0] = NULL;
@@ -624,12 +587,13 @@ int main (int argc, char **argv)
        force = 0;
        buflen = 0;
        quiet = 0;
+       no_erase = 0;
 
        while ((ch = getopt(argc, argv,
 #ifdef FIS_SUPPORT
                        "F:"
 #endif
-                       "frqe:d:j:o:")) != -1)
+                       "frnqe:d:j:p:o:")) != -1)
                switch (ch) {
                        case 'f':
                                force = 1;
@@ -637,6 +601,9 @@ int main (int argc, char **argv)
                        case 'r':
                                boot = 1;
                                break;
+                       case 'n':
+                               no_erase = 1;
+                               break;
                        case 'j':
                                jffs2file = optarg;
                                break;
@@ -654,7 +621,19 @@ int main (int argc, char **argv)
                        case 'd':
                                jffs2dir = optarg;
                                break;
+                       case 'p':
+                               errno = 0;
+                               part_offset = strtoul(optarg, 0, 0);
+                               if (errno) {
+                                       fprintf(stderr, "-p: illegal numeric string\n");
+                                       usage();
+                               }
+                               break;
                        case 'o':
+                               if (!mtd_fixtrx) {
+                                       fprintf(stderr, "-o: is not available on this platform\n");
+                                       usage();
+                               }
                                errno = 0;
                                offset = strtoul(optarg, 0, 0);
                                if (errno) {
@@ -686,9 +665,12 @@ int main (int argc, char **argv)
        } else if ((strcmp(argv[0], "erase") == 0) && (argc == 2)) {
                cmd = CMD_ERASE;
                device = argv[1];
-       } else if ((strcmp(argv[0], "fixtrx") == 0) && (argc == 2)) {
+       } else if (((strcmp(argv[0], "fixtrx") == 0) && (argc == 2)) && mtd_fixtrx) {
                cmd = CMD_FIXTRX;
                device = argv[1];
+       } else if (((strcmp(argv[0], "fixseama") == 0) && (argc == 2)) && mtd_fixseama) {
+               cmd = CMD_FIXSEAMA;
+               device = argv[1];
        } else if ((strcmp(argv[0], "write") == 0) && (argc == 3)) {
                cmd = CMD_WRITE;
                device = argv[2];
@@ -751,7 +733,7 @@ int main (int argc, char **argv)
                case CMD_WRITE:
                        if (!unlocked)
                                mtd_unlock(device);
-                       mtd_write(imagefd, device, fis_layout);
+                       mtd_write(imagefd, device, fis_layout, part_offset);
                        break;
                case CMD_JFFS2WRITE:
                        if (!unlocked)
@@ -762,7 +744,12 @@ int main (int argc, char **argv)
                        mtd_refresh(device);
                        break;
                case CMD_FIXTRX:
-                       mtd_fixtrx(device, offset);
+                   if (mtd_fixtrx) {
+                           mtd_fixtrx(device, offset);
+            }
+               case CMD_FIXSEAMA:
+                       if (mtd_fixseama)
+                           mtd_fixseama(device, 0);
                        break;
        }
 
index a0180319e29d2d290b888e1560cfa4dea4857618..c2133fc37c7dca7f1f6d2ec718454f39f3a8c74f 100644 (file)
@@ -21,8 +21,9 @@ extern int mtd_write_jffs2(const char *mtd, const char *filename, const char *di
 extern int mtd_replace_jffs2(const char *mtd, int fd, int ofs, const char *filename);
 extern void mtd_parse_jffs2data(const char *buf, const char *dir);
 
-/* target specific */
-extern int trx_fixup(int fd, const char *name);
-extern int trx_check(int imagefd, const char *mtd, char *buf, int *len);
-
+/* target specific functions */
+extern int trx_fixup(int fd, const char *name)  __attribute__ ((weak));
+extern int trx_check(int imagefd, const char *mtd, char *buf, int *len) __attribute__ ((weak));
+extern int mtd_fixtrx(const char *mtd, size_t offset) __attribute__ ((weak));
+extern int mtd_fixseama(const char *mtd, size_t offset) __attribute__ ((weak));
 #endif /* __mtd_h */
diff --git a/package/mtd/src/seama.c b/package/mtd/src/seama.c
new file mode 100644 (file)
index 0000000..b0c8bf3
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * seama.c
+ *
+ * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * Based on the trx fixup code:
+ *   Copyright (C) 2005 Mike Baker
+ *   Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <errno.h>
+#include <arpa/inet.h>
+
+#include <sys/ioctl.h>
+#include <mtd/mtd-user.h>
+#include "mtd.h"
+#include "seama.h"
+#include "md5.h"
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define STORE32_LE(X)           ((((X) & 0x000000FF) << 24) | (((X) & 0x0000FF00) << 8) | (((X) & 0x00FF0000) >> 8) | (((X) & 0xFF000000) >> 24))
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define STORE32_LE(X)           (X)
+#else
+#error unknown endianness!
+#endif
+
+ssize_t pread(int fd, void *buf, size_t count, off_t offset);
+ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
+
+int
+seama_fix_md5(char *buf, size_t len)
+{
+       struct seama_hdr *shdr;
+       char *data;
+       size_t msize;
+       size_t isize;
+       MD5_CTX ctx;
+       unsigned char digest[16];
+       int i;
+
+       if (len < sizeof(struct seama_hdr))
+               return -1;
+
+       shdr = (struct seama_hdr *) buf;
+       if (shdr->magic != htonl(SEAMA_MAGIC)) {
+               fprintf(stderr, "no SEAMA header found\n");
+               return -1;
+       }
+
+       isize = ntohl(shdr->size);
+       msize = ntohs(shdr->metasize);
+       if (isize == 0) {
+               /* the image contains no checksum */
+               return -1;
+       }
+
+       len -= sizeof(struct seama_hdr) + sizeof(digest) + msize;
+       if (isize > len)
+               isize = len;
+
+       data = buf + sizeof(struct seama_hdr) + sizeof(digest) + msize;
+
+       MD5_Init(&ctx);
+       MD5_Update(&ctx, data, isize);
+       MD5_Final(digest, &ctx);
+
+       if (!memcmp(digest, &buf[sizeof(struct seama_hdr)], sizeof(digest))) {
+               if (quiet < 2)
+                       fprintf(stderr, "the header is fixed already\n");
+               return -1;
+       }
+
+       if (quiet < 2) {
+               fprintf(stderr, "new size:%u, new MD5: ", isize);
+               for (i = 0; i < sizeof(digest); i++)
+                       fprintf(stderr, "%02x", digest[i]);
+
+               fprintf(stderr, "\n");
+       }
+
+       /* update the size in the image */
+       shdr->size = htonl(isize);
+
+       /* update the checksum in the image */
+       for (i = 0; i < sizeof(digest); i++)
+               buf[sizeof(struct seama_hdr) + i] = digest[i];
+
+       return 0;
+}
+
+int
+mtd_fixseama(const char *mtd, size_t offset)
+{
+       int fd;
+       char *buf;
+       ssize_t res;
+       size_t block_offset;
+
+       if (quiet < 2)
+               fprintf(stderr, "Trying to fix SEAMA header in %s at 0x%x...\n",
+                       mtd, offset);
+
+       block_offset = offset & ~(erasesize - 1);
+       offset -= block_offset;
+
+       fd = mtd_check_open(mtd);
+       if(fd < 0) {
+               fprintf(stderr, "Could not open mtd device: %s\n", mtd);
+               exit(1);
+       }
+
+       if (block_offset + erasesize > mtdsize) {
+               fprintf(stderr, "Offset too large, device size 0x%x\n",
+                       mtdsize);
+               exit(1);
+       }
+
+       buf = malloc(mtdsize);
+       if (!buf) {
+               perror("malloc");
+               exit(1);
+       }
+
+       res = pread(fd, buf, mtdsize, block_offset);
+       if (res != mtdsize) {
+               perror("pread");
+               exit(1);
+       }
+
+       if (seama_fix_md5(buf, mtdsize))
+               goto out;
+
+       if (mtd_erase_block(fd, block_offset)) {
+               fprintf(stderr, "Can't erease block at 0x%x (%s)\n",
+                       block_offset, strerror(errno));
+               exit(1);
+       }
+
+       if (quiet < 2)
+               fprintf(stderr, "Rewriting block at 0x%x\n", block_offset);
+
+       if (pwrite(fd, buf, erasesize, block_offset) != erasesize) {
+               fprintf(stderr, "Error writing block (%s)\n", strerror(errno));
+               exit(1);
+       }
+
+       if (quiet < 2)
+               fprintf(stderr, "Done.\n");
+
+out:
+       close (fd);
+       sync();
+
+       return 0;
+}
+
diff --git a/package/mtd/src/seama.h b/package/mtd/src/seama.h
new file mode 100644 (file)
index 0000000..02683b6
--- /dev/null
@@ -0,0 +1,108 @@
+/* vi: set sw=4 ts=4: */
+/*
+ *     (SEA)ttle i(MA)ge is the image which used in project seattle.
+ *
+ *     Created by David Hsieh <david_hsieh@alphanetworks.com>
+ *     Copyright (C) 2008-2009 Alpha Networks, Inc.
+ *
+ *     This file is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation; either'
+ *     version 2.1 of the License, or (at your option) any later version.
+ *
+ *     The GNU C Library is distributed in the hope that it will be useful,'
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *     Lesser General Public License for more details.
+ *
+ *     You should have received a copy of the GNU Lesser General Public
+ *     License along with the GNU C Library; if not, write to the Free
+ *     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ *     02111-1307 USA.
+ */
+
+#ifndef __SEAMA_HEADER_FILE__
+#define __SEAMA_HEADER_FILE__
+
+#include <stdint.h>
+
+#define SEAMA_MAGIC            0x5EA3A417
+
+/*
+ *     SEAMA looks like the following map.
+ *     All the data of the header should be in network byte order.
+ *
+ *  +-------------+-------------+------------
+ *     | SEAMA magic               |     ^
+ *  +-------------+-------------+     |
+ *     | reserved    | meta size   |     |
+ *  +-------------+-------------+   header
+ *     | image size (0 bytes)      |     |
+ *  +-------------+-------------+     |
+ *     ~ Meta data                 ~     v
+ *  +-------------+-------------+------------
+ *     | SEAMA magic               |   ^     ^
+ *  +-------------+-------------+   |     |
+ *     | reserved    | meta size   |   |     |
+ *  +-------------+-------------+   |     |
+ *     | image size                |   |     |
+ *  +-------------+-------------+ header  |
+ *     |                           |   |     |
+ *     | 16 bytes of MD5 digest    |   |     |
+ *     |                           |   |     |
+ *     |                           |   |     |
+ *  +-------------+-------------+   |     |
+ *     ~ Meta data                 ~   v     |
+ *  +-------------+-------------+-------  |
+ *     |                           |         |
+ *     | Image of the 1st entity   |         |
+ *     ~                           ~ 1st entity
+ *     |                           |         |
+ *     |                           |         v
+ *  +-------------+-------------+-------------
+ *     | SEAMA magic               |   ^     ^
+ *  +-------------+-------------+   |     |
+ *     | reserved    | meta size   |   |     |
+ *  +-------------+-------------+   |     |
+ *     | image size                |   |     |
+ *  +-------------+-------------+ header  |
+ *     |                           |   |     |
+ *     | 16 bytes of MD5 digest    |   |     |
+ *     |                           |   |     |
+ *     |                           |   |     |
+ *  +-------------+-------------+   |     |
+ *     ~ Meta data                 ~   v     |
+ *  +-------------+-------------+-------  |
+ *     |                           |         |
+ *     | Image of the 2nd entity   |         |
+ *     ~                           ~ 2nd entity
+ *     |                           |         |
+ *     |                           |         v
+ *  +-------------+-------------+-------------
+ */
+
+
+/*
+ *     SEAMA header
+ *
+ *     |<-------- 32 bits -------->|
+ *  +-------------+-------------+
+ *     | SEAMA magic               |
+ *  +-------------+-------------+
+ *     | reserved    | meta size   |
+ *  +-------------+-------------+
+ *     | image size                |
+ *  +-------------+-------------+
+ */
+/* seama header */
+typedef struct seama_hdr       seamahdr_t;
+struct seama_hdr
+{
+       uint32_t        magic;                  /* should always be SEAMA_MAGIC. */
+       uint16_t        reserved;               /* reserved for  */
+       uint16_t        metasize;               /* size of the META data */
+       uint32_t        size;                   /* size of the image */
+} __attribute__ ((packed));
+
+
+#endif
index 7094ef62b0c1c80ec163d45c5629bf5ba76c724d..65c24404c2c1fe771acf0f78936b7bbe187a944c 100644 (file)
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <string.h>
+#include <errno.h>
 
 #include <sys/ioctl.h>
-#include "mtd-api.h"
+#include <mtd/mtd-user.h>
 #include "mtd.h"
 #include "crc32.h"
 
 #define TRX_MAGIC       0x30524448      /* "HDR0" */
 struct trx_header {
-       unsigned magic;         /* "HDR0" */
-       unsigned len;           /* Length of file including header */
-       unsigned crc32;         /* 32-bit CRC from flag_version to end of file */
-       unsigned flag_version;  /* 0:15 flags, 16:31 version */
-       unsigned offsets[3];    /* Offsets of partitions from start of header */
+       uint32_t magic;         /* "HDR0" */
+       uint32_t len;           /* Length of file including header */
+       uint32_t crc32;         /* 32-bit CRC from flag_version to end of file */
+       uint32_t flag_version;  /* 0:15 flags, 16:31 version */
+       uint32_t offsets[3];    /* Offsets of partitions from start of header */
 };
 
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define STORE32_LE(X)           ((((X) & 0x000000FF) << 24) | (((X) & 0x0000FF00) << 8) | (((X) & 0x00FF0000) >> 8) | (((X) & 0xFF000000) >> 24))
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define STORE32_LE(X)           (X)
+#else
+#error unknown endianness!
+#endif
+
+ssize_t pread(int fd, void *buf, size_t count, off_t offset);
+ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
+
 int
 trx_fixup(int fd, const char *name)
 {
@@ -130,3 +142,79 @@ trx_check(int imagefd, const char *mtd, char *buf, int *len)
        return 1;
 }
 
+int
+mtd_fixtrx(const char *mtd, size_t offset)
+{
+       int fd;
+       struct trx_header *trx;
+       char *buf;
+       ssize_t res;
+       size_t block_offset;
+
+       if (quiet < 2)
+               fprintf(stderr, "Trying to fix trx header in %s at 0x%x...\n", mtd, offset);
+
+       fd = mtd_check_open(mtd);
+       if(fd < 0) {
+               fprintf(stderr, "Could not open mtd device: %s\n", mtd);
+               exit(1);
+       }
+
+       block_offset = offset & ~(erasesize - 1);
+       offset -= block_offset;
+
+       if (block_offset + erasesize > mtdsize) {
+               fprintf(stderr, "Offset too large, device size 0x%x\n", mtdsize);
+               exit(1);
+       }
+
+       buf = malloc(erasesize);
+       if (!buf) {
+               perror("malloc");
+               exit(1);
+       }
+
+       res = pread(fd, buf, erasesize, block_offset);
+       if (res != erasesize) {
+               perror("pread");
+               exit(1);
+       }
+
+       trx = (struct trx_header *) (buf + offset);
+       if (trx->magic != STORE32_LE(0x30524448)) {
+               fprintf(stderr, "No trx magic found\n");
+               exit(1);
+       }
+
+       if (trx->len == STORE32_LE(erasesize - offset)) {
+               if (quiet < 2)
+                       fprintf(stderr, "Header already fixed, exiting\n");
+               close(fd);
+               return 0;
+       }
+
+       trx->len = STORE32_LE(erasesize - offset);
+
+       trx->crc32 = STORE32_LE(crc32buf((char*) &trx->flag_version, erasesize - offset - 3*4));
+       if (mtd_erase_block(fd, block_offset)) {
+               fprintf(stderr, "Can't erease block at 0x%x (%s)\n", block_offset, strerror(errno));
+               exit(1);
+       }
+
+       if (quiet < 2)
+               fprintf(stderr, "New crc32: 0x%x, rewriting block\n", trx->crc32);
+
+       if (pwrite(fd, buf, erasesize, block_offset) != erasesize) {
+               fprintf(stderr, "Error writing block (%s)\n", strerror(errno));
+               exit(1);
+       }
+
+       if (quiet < 2)
+               fprintf(stderr, "Done.\n");
+
+       close (fd);
+       sync();
+       return 0;
+
+}
+
diff --git a/package/quagga/Makefile b/package/quagga/Makefile
new file mode 100644 (file)
index 0000000..4673e51
--- /dev/null
@@ -0,0 +1,321 @@
+#
+# Copyright (C) 2006-2013 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=quagga
+PKG_VERSION:=1.0.20160315
+PKG_RELEASE:=2
+PKG_MD5SUM:=61bfd0c8fb696dd778234ee8b05821bc
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
+PKG_SOURCE_URL:=http://download.savannah.gnu.org/releases/quagga/
+PKG_CONFIG_DEPENDS:= \
+       CONFIG_IPV6 \
+       CONFIG_PACKAGE_quagga-watchquagga \
+       CONFIG_PACKAGE_quagga-zebra \
+       CONFIG_PACKAGE_quagga-libzebra \
+       CONFIG_PACKAGE_quagga-libospf \
+       CONFIG_PACKAGE_quagga-bgpd \
+       CONFIG_PACKAGE_quagga-isisd \
+       CONFIG_PACKAGE_quagga-ospf6d \
+       CONFIG_PACKAGE_quagga-ripd \
+       CONFIG_PACKAGE_quagga-ripngd \
+       CONFIG_PACKAGE_quagga-babeld \
+       CONFIG_PACKAGE_quagga-vtysh \
+       CONFIG_PACKAGE_quagga-pgbgp
+PKG_BUILD_PARALLEL:=1
+PKG_FIXUP:=autoreconf
+PKG_INSTALL:=1
+
+PATCH_DIR:=patches-pgbgp
+ifeq ($(CONFIG_PACKAGE_quagga-pgbgp),)
+PATCH_DIR:=patches-upstream
+endif
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/quagga/Default
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Routing and Redirection
+  DEPENDS:=quagga
+  TITLE:=The Quagga Software Routing Suite
+  URL:=http://www.quagga.net
+  MAINTAINER:=Vasilis Tsiligiannis <b_tsiligiannis@silverton.gr>
+endef
+
+define Package/quagga
+  $(call Package/quagga/Default)
+  DEPENDS:=+librt
+  MENU:=1
+endef
+
+define Package/quagga/description
+  A routing software package that provides TCP/IP based routing services
+  with routing protocols support such as RIPv1, RIPv2, RIPng, OSPFv2,
+  OSPFv3, BGP-4, and BGP-4+
+endef
+
+define Package/quagga-watchquagga
+  $(call Package/quagga/Default)
+  TITLE:=Quagga watchdog
+  DEPENDS+=+quagga-libzebra
+  DEFAULT:=y if PACKAGE_quagga
+endef
+
+define Package/quagga-zebra
+  $(call Package/quagga/Default)
+  TITLE:=Zebra daemon
+  DEPENDS+=+quagga-libzebra
+  DEFAULT:=y if PACKAGE_quagga
+endef
+
+define Package/quagga-libzebra
+  $(call Package/quagga/Default)
+  TITLE:=zebra library
+endef
+
+define Package/quagga-libospf
+  $(call Package/quagga/Default)
+  TITLE:=OSPF library
+endef
+
+define Package/quagga-bgpd
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libzebra
+  TITLE:=BGPv4, BGPv4+, BGPv4- routing engine
+endef
+
+define Package/quagga-isisd
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libzebra
+  TITLE:=IS-IS routing engine
+endef
+
+define Package/quagga-ospfd
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libospf +quagga-libzebra
+  TITLE:=OSPFv2 routing engine
+endef
+
+define Package/quagga-ospf6d
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libospf +quagga-libzebra @IPV6
+  TITLE:=OSPFv3 routing engine
+endef
+
+define Package/quagga-ripd
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libzebra
+  TITLE:=RIP routing engine
+endef
+
+define Package/quagga-ripngd
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libzebra @IPV6
+  TITLE:=RIPNG routing engine
+endef
+
+define Package/quagga-babeld
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libzebra @IPV6
+  TITLE:=Babel routing engine
+endef
+
+define Package/quagga-vtysh
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-libzebra +libreadline +libncurses
+  TITLE:=integrated shell for Quagga routing software
+endef
+
+define Package/quagga-pgbgp
+  $(call Package/quagga/Default)
+  DEPENDS+=+quagga-bgpd
+  TITLE:=include Pretty Good BGP functionality
+endef
+
+define Package/quagga-zebra/conffiles
+/etc/quagga/zebra.conf
+endef
+
+define Package/quagga-bgpd/conffiles
+/etc/quagga/bgpd.conf
+endef
+
+define Package/quagga-isisd/conffiles
+/etc/quagga/isisd.conf
+endef
+
+define Package/quagga-ospfd/conffiles
+/etc/quagga/ospfd.conf
+endef
+
+define Package/quagga-ospf6d/conffiles
+/etc/quagga/ospf6d.conf
+endef
+
+define Package/quagga-ripd/conffiles
+/etc/quagga/ripd.conf
+endef
+
+define Package/quagga-ripngd/conffiles
+/etc/quagga/ripngd.conf
+endef
+
+define Package/quagga-babeld/conffiles
+/etc/quagga/babeld.conf
+endef
+
+ifneq ($(SDK),)
+CONFIG_PACKAGE_quagga-libzebra:=m
+CONFIG_PACKAGE_quagga-libospf:=m
+CONFIG_PACKAGE_quagga-watchquagga:=m
+CONFIG_PACKAGE_quagga-zebra:=m
+CONFIG_PACKAGE_quagga-bgpd:=m
+CONFIG_PACKAGE_quagga-isisd:=m
+CONFIG_PACKAGE_quagga-ospf6d:=m
+CONFIG_PACKAGE_quagga-ripd:=m
+CONFIG_PACKAGE_quagga-ripngd:=m
+CONFIG_PACKAGE_quagga-babeld:=m
+CONFIG_PACKAGE_quagga-vtysh:=m
+endif
+
+CONFIGURE_ARGS+= \
+       --localstatedir=/var/run/quagga \
+       --sysconfdir=/etc/quagga/ \
+       --enable-shared \
+       --disable-static \
+       --enable-user=network \
+       --enable-group=network \
+       --enable-pie=no \
+       --enable-multipath=8 \
+       --disable-ospfclient \
+       --disable-capabilities \
+       --disable-doc \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-libzebra,zebra) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-libospf,ospfd) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-bgpd,bgpd) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-isisd,isisd) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-ospf6d,ospf6d) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-ripd,ripd) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-ripngd,ripngd) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-babeld,babeld) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-vtysh,vtysh) \
+       $(call autoconf_bool,CONFIG_PACKAGE_quagga-pgbgp,pgbgp) \
+
+MAKE_FLAGS += \
+       CFLAGS="$(TARGET_CFLAGS) -std=gnu99"
+
+define Package/quagga/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) ./files/quagga $(1)/usr/sbin/quagga.init
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/quagga.init $(1)/etc/init.d/quagga
+endef
+
+define Package/quagga-watchquagga/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/watchquagga $(1)/usr/sbin/
+endef
+
+define Package/quagga-zebra/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/zebra $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/zebra.conf
+endef
+
+define Package/quagga-bgpd/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/bgpd $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/bgpd.conf
+endef
+
+define Package/quagga-isisd/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/isisd $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/isisd.conf
+endef
+
+define Package/quagga-ospfd/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ospfd $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/ospfd.conf
+endef
+
+define Package/quagga-ospf6d/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ospf6d $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/ospf6d.conf
+endef
+
+define Package/quagga-ripd/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ripd $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/ripd.conf
+endef
+
+define Package/quagga-ripngd/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ripngd $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/ripngd.conf
+endef
+
+define Package/quagga-babeld/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/babeld $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/quagga
+       chmod 0750 $(1)/etc/quagga
+       $(INSTALL_CONF) ./files/quagga.conf $(1)/etc/quagga/babeld.conf
+endef
+
+define Package/quagga-vtysh/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/vtysh $(1)/usr/bin/
+endef
+
+define Package/quagga-pgbgp/install
+endef
+
+define Package/quagga-libospf/install
+       $(INSTALL_DIR) $(1)/usr/lib
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libospf.so.* $(1)/usr/lib/
+endef
+
+define Package/quagga-libzebra/install
+       $(INSTALL_DIR) $(1)/usr/lib
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libzebra.so.* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,quagga))
+$(eval $(call BuildPackage,quagga-libzebra))
+$(eval $(call BuildPackage,quagga-libospf))
+$(eval $(call BuildPackage,quagga-watchquagga))
+$(eval $(call BuildPackage,quagga-zebra))
+$(eval $(call BuildPackage,quagga-bgpd))
+$(eval $(call BuildPackage,quagga-pgbgp))
+$(eval $(call BuildPackage,quagga-isisd))
+$(eval $(call BuildPackage,quagga-ospfd))
+$(eval $(call BuildPackage,quagga-ospf6d))
+$(eval $(call BuildPackage,quagga-ripd))
+$(eval $(call BuildPackage,quagga-ripngd))
+$(eval $(call BuildPackage,quagga-babeld))
+$(eval $(call BuildPackage,quagga-vtysh))
diff --git a/package/quagga/files/quagga b/package/quagga/files/quagga
new file mode 100644 (file)
index 0000000..b172090
--- /dev/null
@@ -0,0 +1,335 @@
+#!/bin/sh
+#
+# quagga       Starts/stops quagga daemons and watchquagga.
+#              Create a daemon.conf file to have that routing daemon
+#              started/stopped automagically when using this script
+#              without any daemon names as args.
+#              If watchquagga is available, it will also be
+#              started/stopped if the script is called without
+#              any daemon names.
+#
+
+ME=$(basename $0)
+
+usage() {
+       echo "Usage: ${ME} {start|stop|restart} [daemon ...]"
+       exit 2
+}
+
+if [ -z "$1" ]
+then
+       usage
+else
+       COMMAND=$1
+fi
+shift
+ARG_DAEMONS=$*
+BINDIR=/usr/sbin
+CONFDIR=/etc/quagga
+STATEDIR=/var/run/quagga
+RUNUSER=network
+RUNGROUP=$RUNUSER
+DAEMONS="zebra ripd ripngd ospfd ospf6d bgpd"
+DAEMON_FLAGS=-d
+WATCHQUAGGA_FLAGS="-d -z -T 60 -R"
+WATCHQUAGGA_CMD="$0 watchrestart"
+if [ ${COMMAND} != "watchrestart" -a -x "${BINDIR}/watchquagga" ]
+then
+       DAEMONS="${DAEMONS} watchquagga"
+fi
+DAEMONS_STARTSEQ=${DAEMONS}
+
+reverse()
+{
+       local revlist r
+        revlist=
+        for r
+       do
+                revlist="$r $revlist"
+        done
+        echo $revlist
+}
+
+DAEMONS_STOPSEQ=$(reverse ${DAEMONS_STARTSEQ})
+
+#pidof() {
+#      ps ax | awk 'match($5, "(^|/)'"$1"'$") > 0 { printf " %s", $1 }'
+#}
+
+quit() {
+       echo "${ME}: $1"
+       exit 0
+}
+
+die() {
+       echo "${ME}: $1"
+       exit 1
+}
+
+is_in() {
+       local i
+       for i in $2
+       do
+               [ "$1" = "$i" ] && return 0
+       done
+       return 1
+}
+
+select_subset() {
+       local unknown i j
+       unknown=
+       RESULT=
+       for i in $1
+       do
+               is_in $i "$2" || unknown="$unknown $i"
+       done
+       if [ -n "$unknown" ]
+       then
+               RESULT=$unknown
+               return 1
+       else
+               for j in $2
+               do
+                       is_in $j "$1" && RESULT="$RESULT $j"
+               done
+               return 0
+       fi
+}
+
+# check command
+
+case ${COMMAND}
+in
+       start|stop|restart)
+               ;;
+       watchrestart)
+               if [ -n "$ARG_DAEMONS" ]
+               then
+                       echo "${ME}: watchrestart mode is only for use by watchquagga"
+                       exit 2
+               fi
+               ;;
+       *)
+               usage
+               ;;
+esac
+
+# select daemons to start
+
+case ${COMMAND}
+in
+       start|restart|watchrestart)
+               START_DAEMONS=
+               for d in ${DAEMONS_STARTSEQ}
+               do
+                       [ -x "${BINDIR}/${d}" -a -f "${CONFDIR}/${d}.conf" ] \
+                       && START_DAEMONS="${START_DAEMONS}${d} "
+               done
+               WATCHQUAGGA_DAEMONS=${START_DAEMONS}
+               if is_in watchquagga "${DAEMONS_STARTSEQ}"
+               then
+                       START_DAEMONS="${START_DAEMONS} watchquagga"
+               fi
+               if [ -n "${ARG_DAEMONS}" ]
+               then
+                       if select_subset "${ARG_DAEMONS}" "${DAEMONS}"
+                       then
+                               if select_subset "${ARG_DAEMONS}" "${START_DAEMONS}"
+                               then
+                                       START_DAEMONS=${RESULT}
+                               else
+                                       die "these daemons are not startable:${RESULT}."
+                               fi
+                       else
+                               die "unknown daemons:${RESULT}; choose from: ${DAEMONS}."
+                       fi
+               fi
+               ;;
+esac
+
+# select daemons to stop
+
+case ${COMMAND}
+in
+       stop|restart|watchrestart)
+               STOP_DAEMONS=${DAEMONS_STOPSEQ}
+               if [ -n "${ARG_DAEMONS}" ]
+               then
+                       if select_subset "${ARG_DAEMONS}" "${STOP_DAEMONS}"
+                       then
+                               STOP_DAEMONS=${RESULT}
+                       else
+                               die "unknown daemons:${RESULT}; choose from: ${DAEMONS}."
+                       fi
+               fi
+               stop_daemons=
+               for d in ${STOP_DAEMONS}
+               do
+                       pidfile=${STATEDIR}/${d}.pid
+                       if [ -f "${pidfile}" -o -n "$(pidof ${d})" ]
+                       then
+                               stop_daemons="${stop_daemons}${d} "
+                       elif [ -n "${ARG_DAEMONS}" ]
+                       then
+                               echo "${ME}: found no ${d} process running."
+                       fi
+               done
+               STOP_DAEMONS=${stop_daemons}
+               ;;
+esac
+
+# stop daemons
+
+for d in $STOP_DAEMONS
+do
+       echo -n "${ME}: Stopping ${d} ... "
+       pidfile=${STATEDIR}/${d}.pid
+       if [ -f "${pidfile}" ]
+       then
+               file_pid=$(cat ${pidfile})
+               if [ -z "${file_pid}" ]
+               then
+                       echo -n "no pid file entry found ... "
+               fi
+       else
+               file_pid=
+               echo -n "no pid file found ... "
+       fi
+       proc_pid=$(pidof ${d})
+       if [ -z "${proc_pid}" ]
+       then
+               echo -n "found no ${d} process running ... "
+       else
+               count=0
+               notinpidfile=
+               for p in ${proc_pid}
+               do
+                       count=$((${count}+1))
+                       if kill ${p}
+                       then
+                               echo -n "killed ${p} ... "
+                       else
+                               echo -n "failed to kill ${p} ... "
+                       fi
+                       [ "${p}" = "${file_pid}" ] \
+                       || notinpidfile="${notinpidfile} ${p}"
+               done
+               [ ${count} -le 1 ] \
+               || echo -n "WARNING: ${count} ${d} processes were found running ... "
+               for n in ${notinpidfile}
+               do
+                       echo -n "WARNING: process ${n} was not in pid file ... "
+               done
+       fi
+       count=0
+       survivors=$(pidof ${d})
+       while [ -n "${survivors}" ]
+       do
+               sleep 1
+               count=$((${count}+1))
+               survivors=$(pidof ${d})
+               [ -z "${survivors}" -o ${count} -gt 5 ] && break
+               for p in ${survivors}
+               do
+                       sleep 1
+                       echo -n "${p} "
+                       kill ${p}
+               done
+       done
+       survivors=$(pidof ${d})
+       [ -n "${survivors}" ] && \
+       if kill -KILL ${survivors}
+       then
+               echo -n "KILLed ${survivors} ... "
+       else
+               echo -n "failed to KILL ${survivors} ... "
+       fi
+       sleep 1
+       survivors=$(pidof ${d})
+       if [ -z "${survivors}" ]
+       then
+               echo -n "done."
+               if [ -f "${pidfile}" ]
+               then
+                       rm -f ${pidfile} \
+                       || echo -n " Failed to remove pidfile."
+               fi
+       else
+               echo -n "failed to stop ${survivors} - giving up."
+               if [ "${survivors}" != "${file_pid}" ]
+               then
+                       if echo "${survivors}" > ${pidfile}
+                       then
+                               chown ${RUNUSER}:${RUNGROUP} ${pidfile}
+                               echo -n " Wrote ${survivors} to pidfile."
+                       else
+                               echo -n " Failed to write ${survivors} to pidfile."
+                       fi
+               fi
+       fi
+       echo
+done
+
+# start daemons
+
+if [ -n "$START_DAEMONS" ]
+then
+       [ -d ${CONFDIR} ] \
+       || quit "${ME}: no config directory ${CONFDIR} - exiting."
+       chown -R ${RUNUSER}:${RUNGROUP} ${CONFDIR}
+       [ -d ${STATEDIR} ] || mkdir -p ${STATEDIR} \
+       || die "${ME}: could not create state directory ${STATEDIR} - exiting."
+       chown -R ${RUNUSER}:${RUNGROUP} ${STATEDIR}
+
+       for d in $START_DAEMONS
+       do
+               echo -n "${ME}: Starting ${d} ... "
+               proc_pid=$(pidof ${d})
+               pidfile=${STATEDIR}/${d}.pid
+               file_pid=
+               if [ -f "${pidfile}" ]
+               then
+                       file_pid=$(cat ${pidfile})
+                       if [ -n "${file_pid}" ]
+                       then
+                               echo -n "found old pid file entry ${file_pid} ... "
+                       fi
+               fi
+               if [ -n "${proc_pid}" ]
+               then
+                       echo -n "found ${d} running (${proc_pid}) - skipping ${d}."
+                       if [ "${proc_pid}" != "${file_pid}" ]
+                       then
+                               if echo "${proc_pid}" > ${pidfile}
+                               then
+                                       chown ${RUNUSER}:${RUNGROUP} ${pidfile}
+                                       echo -n " Wrote ${proc_pid} to pidfile."
+                               else
+                                       echo -n " Failed to write ${proc_pid} to pidfile."
+                               fi
+                       fi
+               elif rm -f "${pidfile}"
+               then
+                       if [ "${d}" = "watchquagga" ]
+                       then
+                               "${BINDIR}/${d}" \
+                                       ${WATCHQUAGGA_FLAGS} \
+                                       "${WATCHQUAGGA_CMD}" \
+                                       ${WATCHQUAGGA_DAEMONS}
+                               status=$?
+                       else
+                               "${BINDIR}/${d}" ${DAEMON_FLAGS}
+                               status=$?
+                       fi
+                       if [ $status -eq 0 ]
+                       then
+                               echo -n "done."
+                       else
+                               echo -n "failed."
+                       fi
+               else
+                       echo -n " failed to remove pidfile."
+               fi
+               echo
+       done
+fi
diff --git a/package/quagga/files/quagga.conf b/package/quagga/files/quagga.conf
new file mode 100644 (file)
index 0000000..fb7a54e
--- /dev/null
@@ -0,0 +1,7 @@
+password zebra
+!
+access-list vty permit 127.0.0.0/8
+access-list vty deny any
+!
+line vty
+ access-class vty
diff --git a/package/quagga/files/quagga.init b/package/quagga/files/quagga.init
new file mode 100644 (file)
index 0000000..21fbf2c
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006 OpenWrt.org
+
+START=60
+start() {
+       /usr/sbin/quagga.init start
+}
+
+stop() {
+       /usr/sbin/quagga.init stop
+}
diff --git a/package/quagga/not-patches/patches-nopes/120-quagga_manet.patch b/package/quagga/not-patches/patches-nopes/120-quagga_manet.patch
new file mode 100644 (file)
index 0000000..4277704
--- /dev/null
@@ -0,0 +1,243 @@
+--- a/lib/log.c
++++ b/lib/log.c
+@@ -925,13 +925,19 @@ proto_redistnum(int afi, const char *s)
+       return ZEBRA_ROUTE_STATIC;
+       else if (strncmp (s, "r", 1) == 0)
+       return ZEBRA_ROUTE_RIP;
+-      else if (strncmp (s, "o", 1) == 0)
++      else if (strncmp (s, "os", 2) == 0)
+       return ZEBRA_ROUTE_OSPF;
+       else if (strncmp (s, "i", 1) == 0)
+       return ZEBRA_ROUTE_ISIS;
+       else if (strncmp (s, "bg", 2) == 0)
+       return ZEBRA_ROUTE_BGP;
+-      else if (strncmp (s, "ba", 2) == 0)
++      else if (strncmp (s, "h", 1) == 0)
++      return ZEBRA_ROUTE_HSLS;
++      else if (strncmp (s, "ol", 2) == 0)
++      return ZEBRA_ROUTE_OLSR;
++      else if (strncmp (s, "bat", 3) == 0)
++      return ZEBRA_ROUTE_BATMAN;
++      else if (strncmp (s, "bab", 3) == 0)
+       return ZEBRA_ROUTE_BABEL;
+     }
+   if (afi == AFI_IP6)
+@@ -944,13 +950,19 @@ proto_redistnum(int afi, const char *s)
+       return ZEBRA_ROUTE_STATIC;
+       else if (strncmp (s, "r", 1) == 0)
+       return ZEBRA_ROUTE_RIPNG;
+-      else if (strncmp (s, "o", 1) == 0)
++      else if (strncmp (s, "os", 2) == 0)
+       return ZEBRA_ROUTE_OSPF6;
+       else if (strncmp (s, "i", 1) == 0)
+       return ZEBRA_ROUTE_ISIS;
+       else if (strncmp (s, "bg", 2) == 0)
+       return ZEBRA_ROUTE_BGP;
+-      else if (strncmp (s, "ba", 2) == 0)
++      else if (strncmp (s, "h", 1) == 0)
++      return ZEBRA_ROUTE_HSLS;
++      else if (strncmp (s, "ol", 2) == 0)
++      return ZEBRA_ROUTE_OLSR;
++      else if (strncmp (s, "bat", 3) == 0)
++      return ZEBRA_ROUTE_BATMAN;
++      else if (strncmp (s, "bab", 3) == 0)
+       return ZEBRA_ROUTE_BABEL;
+     }
+   return -1;
+--- a/lib/route_types.txt
++++ b/lib/route_types.txt
+@@ -51,13 +51,9 @@ ZEBRA_ROUTE_OSPF,       ospf,      ospfd
+ ZEBRA_ROUTE_OSPF6,      ospf6,     ospf6d, 'O', 0, 1, "OSPFv6"
+ ZEBRA_ROUTE_ISIS,       isis,      isisd,  'I', 1, 1, "IS-IS"
+ ZEBRA_ROUTE_BGP,        bgp,       bgpd,   'B', 1, 1, "BGP"
+-# HSLS and OLSR both are AFI independent (so: 1, 1), however
+-# we want to disable for them for general Quagga distribution.
+-# This at least makes it trivial for users of these protocols
+-# to 'switch on' redist support (direct numeric entry remaining
+-# possible).
+-ZEBRA_ROUTE_HSLS,       hsls,      hslsd,  'H', 0, 0, "HSLS"
+-ZEBRA_ROUTE_OLSR,       olsr,      olsrd,  'o', 0, 0, "OLSR"
++ZEBRA_ROUTE_HSLS,       hsls,      hslsd,  'H', 1, 1, "HSLS"
++ZEBRA_ROUTE_OLSR,       olsr,      olsrd,  'o', 1, 1, "OLSR"
++ZEBRA_ROUTE_BATMAN,     batman,    batmand,'b', 1, 1, "BATMAN"
+ ZEBRA_ROUTE_BABEL,      babel,     babeld, 'A', 1, 1, "Babel"
+ ## help strings
+@@ -72,5 +68,6 @@ ZEBRA_ROUTE_OSPF6,  "Open Shortest Path
+ ZEBRA_ROUTE_ISIS,   "Intermediate System to Intermediate System (IS-IS)"
+ ZEBRA_ROUTE_BGP,    "Border Gateway Protocol (BGP)"
+ ZEBRA_ROUTE_HSLS,   "Hazy-Sighted Link State Protocol (HSLS)"
+-ZEBRA_ROUTE_OLSR,   "Optimised Link State Routing (OLSR)"
++ZEBRA_ROUTE_OLSR,   "Optimized Link State Routing (OLSR)"
++ZEBRA_ROUTE_BATMAN, "Better Approach to Mobile Ad-Hoc Networking (BATMAN)"
+ ZEBRA_ROUTE_BABEL,  "Babel routing protocol (Babel)"
+--- a/ripd/rip_zebra.c
++++ b/ripd/rip_zebra.c
+@@ -206,9 +206,12 @@ static struct {
+   {ZEBRA_ROUTE_KERNEL,  1, "kernel"},
+   {ZEBRA_ROUTE_CONNECT, 1, "connected"},
+   {ZEBRA_ROUTE_STATIC,  1, "static"},
+-  {ZEBRA_ROUTE_OSPF,    1, "ospf"},
++  {ZEBRA_ROUTE_OSPF,    2, "ospf"},
+   {ZEBRA_ROUTE_BGP,     2, "bgp"},
+-  {ZEBRA_ROUTE_BABEL,   2, "babel"},
++  {ZEBRA_ROUTE_HSLS,    1, "hsls"},
++  {ZEBRA_ROUTE_OLSR,    2, "olsr"},
++  {ZEBRA_ROUTE_BATMAN,  3, "batman"},
++  {ZEBRA_ROUTE_BABEL,   3, "babel"},
+   {0, 0, NULL}
+ };
+--- a/ripngd/ripng_zebra.c
++++ b/ripngd/ripng_zebra.c
+@@ -216,9 +216,12 @@ static struct {
+   {ZEBRA_ROUTE_KERNEL,  1, "kernel"},
+   {ZEBRA_ROUTE_CONNECT, 1, "connected"},
+   {ZEBRA_ROUTE_STATIC,  1, "static"},
+-  {ZEBRA_ROUTE_OSPF6,   1, "ospf6"},
++  {ZEBRA_ROUTE_OSPF6,   2, "ospf6"},
+   {ZEBRA_ROUTE_BGP,     2, "bgp"},
+-  {ZEBRA_ROUTE_BABEL,   2, "babel"},
++  {ZEBRA_ROUTE_HSLS,    1, "hsls"},
++  {ZEBRA_ROUTE_OLSR,    2, "olsr"},
++  {ZEBRA_ROUTE_BATMAN,  3, "batman"},
++  {ZEBRA_ROUTE_BABEL,   3, "babel"},
+   {0, 0, NULL}
+ };
+--- a/zebra/rt_netlink.c
++++ b/zebra/rt_netlink.c
+@@ -1810,6 +1810,9 @@ netlink_route_multipath (int cmd, struct
+       if (rta->rta_len > RTA_LENGTH (0))
+         addattr_l (&req.n, NL_PKT_BUF_SIZE, RTA_MULTIPATH, RTA_DATA (rta),
+                    RTA_PAYLOAD (rta));
++
++     if (rib->type == ZEBRA_ROUTE_OLSR)
++       req.r.rtm_scope = RT_SCOPE_LINK;
+     }
+   /* If there is no useful nexthop then return. */
+--- a/zebra/zebra_rib.c
++++ b/zebra/zebra_rib.c
+@@ -68,6 +68,9 @@ static const struct
+   [ZEBRA_ROUTE_OSPF6]   = {ZEBRA_ROUTE_OSPF6,   110},
+   [ZEBRA_ROUTE_ISIS]    = {ZEBRA_ROUTE_ISIS,    115},
+   [ZEBRA_ROUTE_BGP]     = {ZEBRA_ROUTE_BGP,      20  /* IBGP is 200. */},
++  [ZEBRA_ROUTE_HSLS]    = {ZEBRA_ROUTE_HSLS,      0},
++  [ZEBRA_ROUTE_OLSR]    = {ZEBRA_ROUTE_OLSR,      0},
++  [ZEBRA_ROUTE_BATMAN]  = {ZEBRA_ROUTE_BATMAN,    0},
+   [ZEBRA_ROUTE_BABEL]   = {ZEBRA_ROUTE_BABEL,    95},
+   /* no entry/default: 150 */
+ };
+@@ -538,6 +541,18 @@ nexthop_active_ipv4 (struct rib *rib, st
+                 }
+             return resolved;
+           }
++        else if (match->type == ZEBRA_ROUTE_OLSR)
++          {
++            for (newhop = match->nexthop; newhop; newhop = newhop->next)
++              if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)
++                  && newhop->type == NEXTHOP_TYPE_IFINDEX)
++                {
++                  if (nexthop->type == NEXTHOP_TYPE_IPV4)
++                    nexthop->ifindex = newhop->ifindex;
++                  return 1;
++                }
++            return 0;
++          }
+         else
+           {
+             return 0;
+@@ -674,6 +689,18 @@ nexthop_active_ipv6 (struct rib *rib, st
+                 }
+             return resolved;
+           }
++        else if (match->type == ZEBRA_ROUTE_OLSR)
++          {
++            for (newhop = match->nexthop; newhop; newhop = newhop->next)
++              if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)
++                  && newhop->type == NEXTHOP_TYPE_IFINDEX)
++                {
++                  if (nexthop->type == NEXTHOP_TYPE_IPV6)
++                    nexthop->ifindex = newhop->ifindex;
++                  return 1;
++                }
++            return 0;
++          }
+         else
+           {
+             return 0;
+@@ -1509,6 +1536,8 @@ static const u_char meta_queue_map[ZEBRA
+   [ZEBRA_ROUTE_ISIS]    = 2,
+   [ZEBRA_ROUTE_BGP]     = 3,
+   [ZEBRA_ROUTE_HSLS]    = 4,
++  [ZEBRA_ROUTE_OLSR]    = 4,
++  [ZEBRA_ROUTE_BATMAN]  = 4,
+   [ZEBRA_ROUTE_BABEL]   = 2,
+ };
+--- a/zebra/zebra_snmp.c
++++ b/zebra/zebra_snmp.c
+@@ -245,6 +245,12 @@ proto_trans(int type)
+       return 1; /* shouldn't happen */
+     case ZEBRA_ROUTE_BGP:
+       return 14; /* bgp */
++    case ZEBRA_ROUTE_HSLS:
++      return 1; /* other */
++    case ZEBRA_ROUTE_OLSR:
++      return 1; /* other */
++    case ZEBRA_ROUTE_BATMAN:
++      return 1; /* other */
+     default:
+       return 1; /* other */
+     }
+--- a/zebra/zebra_vty.c
++++ b/zebra/zebra_vty.c
+@@ -559,7 +559,10 @@ vty_show_ip_route_detail (struct vty *vt
+         || rib->type == ZEBRA_ROUTE_OSPF
+         || rib->type == ZEBRA_ROUTE_BABEL
+         || rib->type == ZEBRA_ROUTE_ISIS
+-        || rib->type == ZEBRA_ROUTE_BGP)
++        || rib->type == ZEBRA_ROUTE_BGP
++        || rib->type == ZEBRA_ROUTE_HSLS
++        || rib->type == ZEBRA_ROUTE_OLSR
++        || rib->type == ZEBRA_ROUTE_BATMAN)
+       {
+         time_t uptime;
+         struct tm *tm;
+@@ -754,7 +757,10 @@ vty_show_ip_route (struct vty *vty, stru
+         || rib->type == ZEBRA_ROUTE_OSPF
+         || rib->type == ZEBRA_ROUTE_BABEL
+         || rib->type == ZEBRA_ROUTE_ISIS
+-        || rib->type == ZEBRA_ROUTE_BGP)
++        || rib->type == ZEBRA_ROUTE_BGP
++        || rib->type == ZEBRA_ROUTE_HSLS
++        || rib->type == ZEBRA_ROUTE_OLSR
++        || rib->type == ZEBRA_ROUTE_BATMAN)
+       {
+         time_t uptime;
+         struct tm *tm;
+@@ -1550,7 +1556,10 @@ vty_show_ipv6_route_detail (struct vty *
+         || rib->type == ZEBRA_ROUTE_OSPF6
+         || rib->type == ZEBRA_ROUTE_BABEL
+         || rib->type == ZEBRA_ROUTE_ISIS
+-        || rib->type == ZEBRA_ROUTE_BGP)
++        || rib->type == ZEBRA_ROUTE_BGP
++        || rib->type == ZEBRA_ROUTE_HSLS
++        || rib->type == ZEBRA_ROUTE_OLSR
++        || rib->type == ZEBRA_ROUTE_BATMAN)
+       {
+         time_t uptime;
+         struct tm *tm;
+@@ -1692,7 +1701,10 @@ vty_show_ipv6_route (struct vty *vty, st
+         || rib->type == ZEBRA_ROUTE_OSPF6
+         || rib->type == ZEBRA_ROUTE_BABEL
+         || rib->type == ZEBRA_ROUTE_ISIS
+-        || rib->type == ZEBRA_ROUTE_BGP)
++        || rib->type == ZEBRA_ROUTE_BGP
++        || rib->type == ZEBRA_ROUTE_HSLS
++        || rib->type == ZEBRA_ROUTE_OLSR
++        || rib->type == ZEBRA_ROUTE_BATMAN)
+       {
+         time_t uptime;
+         struct tm *tm;
diff --git a/package/quagga/not-patches/patches-nopes/158-next-hop-self_all.patch b/package/quagga/not-patches/patches-nopes/158-next-hop-self_all.patch
new file mode 100644 (file)
index 0000000..6bfb800
--- /dev/null
@@ -0,0 +1,131 @@
+From: Timo Teräs <timo.teras@iki.fi>
+Date: Thu, 24 Apr 2014 07:22:37 +0000 (+0300)
+Subject: bgpd: implement "next-hop-self all"
+X-Git-Url: http://git.ozo.com/?p=quagga%2F.git;a=commitdiff_plain;h=9e7a53c179f6897128b24435452b5d3d0f8c715a
+
+bgpd: implement "next-hop-self all"
+
+As specified in:
+http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/iproute_bgp/command/irg-cr-book/bgp-m1.html#wp4972925610
+
+This allows overriding next-hop for ibgp learned routes on an
+RR for reflected routes.
+
+Especially useful for using iBGP in DMVPN setups. See:
+http://blog.ipspace.net/2014/04/changes-in-ibgp-next-hop-processing.html
+
+Signed-off-by: Timo Teräs <timo.teras@iki.fi>
+---
+
+--- a/bgpd/bgp_route.c
++++ b/bgpd/bgp_route.c
+@@ -973,7 +973,8 @@ bgp_announce_check (struct bgp_info *ri,
+     }
+   /* next-hop-set */
+-  if (transparent || reflect
++  if (transparent
++      || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
+       || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
+         && ((p->family == AF_INET && attr->nexthop.s_addr)
+ #ifdef HAVE_IPV6
+--- a/bgpd/bgp_vty.c
++++ b/bgpd/bgp_vty.c
+@@ -2093,25 +2093,41 @@ DEFUN (no_neighbor_capability_orf_prefix
+ /* neighbor next-hop-self. */
+ DEFUN (neighbor_nexthop_self,
+        neighbor_nexthop_self_cmd,
+-       NEIGHBOR_CMD2 "next-hop-self",
++       NEIGHBOR_CMD2 "next-hop-self {all}",
+        NEIGHBOR_STR
+        NEIGHBOR_ADDR_STR2
+-       "Disable the next hop calculation for this neighbor\n")
++       "Disable the next hop calculation for this neighbor\n"
++       "Apply also to ibgp-learned routes when acting as a route reflector\n")
+ {
+-  return peer_af_flag_set_vty (vty, argv[0], bgp_node_afi (vty),
+-                             bgp_node_safi (vty), PEER_FLAG_NEXTHOP_SELF);
++  u_int32_t flags = PEER_FLAG_NEXTHOP_SELF, unset = 0;
++  int rc;
++
++  /* Check if "all" is specified */
++  if (argv[1] != NULL)
++    flags |= PEER_FLAG_NEXTHOP_SELF_ALL;
++  else
++    unset |= PEER_FLAG_NEXTHOP_SELF_ALL;
++
++  rc = peer_af_flag_set_vty (vty, argv[0], bgp_node_afi (vty),
++                           bgp_node_safi (vty), flags);
++  if ( rc == CMD_SUCCESS && unset )
++    rc = peer_af_flag_unset_vty (vty, argv[0], bgp_node_afi (vty),
++                               bgp_node_safi (vty), unset);
++  return rc;
+ }
+ DEFUN (no_neighbor_nexthop_self,
+        no_neighbor_nexthop_self_cmd,
+-       NO_NEIGHBOR_CMD2 "next-hop-self",
++       NO_NEIGHBOR_CMD2 "next-hop-self {all}",
+        NO_STR
+        NEIGHBOR_STR
+        NEIGHBOR_ADDR_STR2
+-       "Disable the next hop calculation for this neighbor\n")
++       "Disable the next hop calculation for this neighbor\n"
++       "Apply also to ibgp-learned routes when acting as a route reflector\n")
+ {
+   return peer_af_flag_unset_vty (vty, argv[0], bgp_node_afi (vty),
+-                               bgp_node_safi (vty), PEER_FLAG_NEXTHOP_SELF);
++                               bgp_node_safi (vty),
++                               PEER_FLAG_NEXTHOP_SELF|PEER_FLAG_NEXTHOP_SELF_ALL);
+ }
+ /* neighbor remove-private-AS. */
+--- a/bgpd/bgpd.c
++++ b/bgpd/bgpd.c
+@@ -2355,6 +2355,7 @@ static const struct peer_flag_action pee
+     { PEER_FLAG_ORF_PREFIX_SM,            1, peer_change_reset },
+     { PEER_FLAG_ORF_PREFIX_RM,            1, peer_change_reset },
+     { PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED,  0, peer_change_reset_out },
++    { PEER_FLAG_NEXTHOP_SELF_ALL,         1, peer_change_reset_out },
+     { 0, 0, 0 }
+   };
+@@ -4990,7 +4991,9 @@ bgp_config_write_peer (struct vty *vty,
+   /* Nexthop self. */
+   if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)
+       && ! peer->af_group[afi][safi])
+-    vty_out (vty, " neighbor %s next-hop-self%s", addr, VTY_NEWLINE);
++    vty_out (vty, " neighbor %s next-hop-self%s%s", addr,
++           peer_af_flag_check (peer, afi, safi, PEER_FLAG_NEXTHOP_SELF_ALL) ?
++           " all" : "", VTY_NEWLINE);
+   /* Remove private AS. */
+   if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
+--- a/bgpd/bgpd.h
++++ b/bgpd/bgpd.h
+@@ -412,6 +412,7 @@ struct peer
+ #define PEER_FLAG_MAX_PREFIX                (1 << 14) /* maximum prefix */
+ #define PEER_FLAG_MAX_PREFIX_WARNING        (1 << 15) /* maximum prefix warning-only */
+ #define PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED   (1 << 16) /* leave link-local nexthop unchanged */
++#define PEER_FLAG_NEXTHOP_SELF_ALL          (1 << 17) /* next-hop-self all */
+   /* MD5 password */
+   char *password;
+--- a/doc/bgpd.texi
++++ b/doc/bgpd.texi
+@@ -299,10 +299,12 @@ This command is deprecated and may be re
+ use should be avoided.
+ @end deffn
+-@deffn {BGP} {neighbor @var{peer} next-hop-self} {}
+-@deffnx {BGP} {no neighbor @var{peer} next-hop-self} {}
++@deffn {BGP} {neighbor @var{peer} next-hop-self [all]} {}
++@deffnx {BGP} {no neighbor @var{peer} next-hop-self [all]} {}
+ This command specifies an announced route's nexthop as being equivalent
+-to the address of the bgp router.
++to the address of the bgp router if it is learned via eBGP.
++If the optional keyword @code{all} is specified the modifiation is done
++also for routes learned via iBGP.
+ @end deffn
+ @deffn {BGP} {neighbor @var{peer} update-source @var{<ifname|address>}} {}
diff --git a/package/quagga/not-patches/patches-nopes/159-share_aspath.patch b/package/quagga/not-patches/patches-nopes/159-share_aspath.patch
new file mode 100644 (file)
index 0000000..cd5a669
--- /dev/null
@@ -0,0 +1,115 @@
+From: Timo Teräs <timo.teras@iki.fi>
+Date: Tue, 20 May 2014 06:04:49 +0000 (+0300)
+Subject: bgpd: route-map: share aspath object compilation code where possible
+X-Git-Url: http://git.ozo.com/?p=quagga%2F.git;a=commitdiff_plain;h=b304dcb8abc4e5b93f86a4024990980746e730be
+
+bgpd: route-map: share aspath object compilation code where possible
+
+Signed-off-by: Timo Teräs <timo.teras@iki.fi>
+---
+
+--- a/bgpd/bgp_routemap.c
++++ b/bgpd/bgp_routemap.c
+@@ -101,6 +101,26 @@ o Local extention
+ */ 
++ /* generic as path object to be shared in multiple rules */
++
++static void *
++route_aspath_compile (const char *arg)
++{
++  struct aspath *aspath;
++
++  aspath = aspath_str2aspath (arg);
++  if (! aspath)
++    return NULL;
++  return aspath;
++}
++
++static void
++route_aspath_free (void *rule)
++{
++  struct aspath *aspath = rule;
++  aspath_free (aspath);
++}
++
+  /* 'match peer (A.B.C.D|X:X::X:X)' */
+ /* Compares the peer specified in the 'match peer' clause with the peer
+@@ -1228,33 +1248,13 @@ route_set_aspath_prepend (void *rule, st
+   return RMAP_OKAY;
+ }
+-/* Compile function for as-path prepend. */
+-static void *
+-route_set_aspath_prepend_compile (const char *arg)
+-{
+-  struct aspath *aspath;
+-
+-  aspath = aspath_str2aspath (arg);
+-  if (! aspath)
+-    return NULL;
+-  return aspath;
+-}
+-
+-/* Compile function for as-path prepend. */
+-static void
+-route_set_aspath_prepend_free (void *rule)
+-{
+-  struct aspath *aspath = rule;
+-  aspath_free (aspath);
+-}
+-
+ /* Set metric rule structure. */
+ struct route_map_rule_cmd route_set_aspath_prepend_cmd = 
+ {
+   "as-path prepend",
+   route_set_aspath_prepend,
+-  route_set_aspath_prepend_compile,
+-  route_set_aspath_prepend_free,
++  route_aspath_compile,
++  route_aspath_free,
+ };
+ /* `set as-path exclude ASn' */
+@@ -1282,37 +1282,13 @@ route_set_aspath_exclude (void *rule, st
+   return RMAP_OKAY;
+ }
+-/* FIXME: consider using route_set_aspath_prepend_compile() and
+- * route_set_aspath_prepend_free(), which two below function are
+- * exact clones of.
+- */
+-
+-/* Compile function for as-path exclude. */
+-static void *
+-route_set_aspath_exclude_compile (const char *arg)
+-{
+-  struct aspath *aspath;
+-
+-  aspath = aspath_str2aspath (arg);
+-  if (! aspath)
+-    return NULL;
+-  return aspath;
+-}
+-
+-static void
+-route_set_aspath_exclude_free (void *rule)
+-{
+-  struct aspath *aspath = rule;
+-  aspath_free (aspath);
+-}
+-
+ /* Set ASn exlude rule structure. */
+ struct route_map_rule_cmd route_set_aspath_exclude_cmd = 
+ {
+   "as-path exclude",
+   route_set_aspath_exclude,
+-  route_set_aspath_exclude_compile,
+-  route_set_aspath_exclude_free,
++  route_aspath_compile,
++  route_aspath_free,
+ };
+ /* `set community COMMUNITY' */
diff --git a/package/quagga/not-patches/patches-old/100-bgpd_Display_configured_dampening_parameters.patch b/package/quagga/not-patches/patches-old/100-bgpd_Display_configured_dampening_parameters.patch
new file mode 100644 (file)
index 0000000..