[PATCH 2/2] interface-ip: copy more info for target host route

2021-11-22 Thread luizluca
From: Luiz Angelo Daros de Luca 

interface_ip_add_target_route was adding a host route without
copying other confs like type, source, online). The result was that this:

  unreachable 192.168.0.9  metric 123

was being converted to:

  192.168.0.9 dev lo scope link  metric 123

valid_until is still not copied but I'm not sure if it is needed as this
route might get updated when the source route is refreshed/expired.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 interface-ip.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/interface-ip.c b/interface-ip.c
index 7b63ef9..6fdbf18 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -300,12 +300,17 @@ interface_ip_add_target_route(union if_addr *addr, bool 
v6, struct interface *if
return NULL;
 
route->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
+   route->flags |= r->next & (DEVROUTE_MTU | DEVROUTE_METRIC |
+   DEVROUTE_TYPE | DEVROUTE_ONLINK | DEVROUTE_TABLE);
route->mask = v6 ? 128 : 32;
memcpy(>addr, addr, addrsize);
memcpy(>nexthop, _next->nexthop, sizeof(route->nexthop));
route->mtu = r_next->mtu;
route->metric = r_next->metric;
route->table = r_next->table;
+   route->type = r_next->type;
+   memcpy(>source, _next->source, addrsize);
+   route->sourcemask = r_next->sourcemask;
route->iface = iface;
vlist_add(>host_routes, >node, route);
 
-- 
2.33.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH 1/2] interface-ip: use metric when looking for a route

2021-11-22 Thread luizluca
From: Luiz Angelo Daros de Luca 

When there were multiple routes with the same target but different
metrics, __find_ip_route_target was returning the first one,
independently of the metric.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 interface-ip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/interface-ip.c b/interface-ip.c
index 648f521..7b63ef9 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -234,7 +234,9 @@ __find_ip_route_target(struct interface_ip_settings *ip, 
union if_addr *a,
if (route->flags & DEVROUTE_TABLE)
continue;
 
-   if (!*res || route->mask > (*res)->mask)
+   if (!*res || route->mask > (*res)->mask ||
+   ((route->mask == (*res)->mask) && (route->flags & 
DEVROUTE_METRIC)
+&& (route->metric < (*res)->metric)))
*res = route;
}
 }
-- 
2.33.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH 1/2] interface-ip: copy more info for target host route

2021-10-26 Thread luizluca
From: Luiz Angelo Daros de Luca 

interface_ip_add_target_route was adding a host route without
copying other confs like type, source, online). The result was that this:

  unreachable 192.168.0.9  metric 123

was being converted to:

  192.168.0.9 dev lo scope link  metric 123

Signed-off-by: Luiz Angelo Daros de Luca 
---
 interface-ip.c | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/interface-ip.c b/interface-ip.c
index 648f521..7c60fec 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -301,9 +301,26 @@ interface_ip_add_target_route(union if_addr *addr, bool 
v6, struct interface *if
route->mask = v6 ? 128 : 32;
memcpy(>addr, addr, addrsize);
memcpy(>nexthop, _next->nexthop, sizeof(route->nexthop));
-   route->mtu = r_next->mtu;
-   route->metric = r_next->metric;
-   route->table = r_next->table;
+   if (r_next->flags & DEVROUTE_MTU) {
+   route->mtu = r_next->mtu;
+   route->flags |= DEVROUTE_MTU;
+   }
+   if (r_next->flags & DEVROUTE_METRIC) {
+   route->metric = r_next->metric;
+   route->flags |= DEVROUTE_METRIC;
+   }
+   if (r_next->flags & DEVROUTE_TABLE) {
+   route->table = r_next->table;
+   route->flags |= DEVROUTE_TABLE;
+   }
+   if (r_next->flags & DEVROUTE_TYPE) {
+   route->type = r_next->type;
+   route->flags |= DEVROUTE_TYPE;
+   }
+   if (r_next->flags & DEVROUTE_ONLINK)
+   route->flags |= DEVROUTE_ONLINK;
+   memcpy(>source, _next->source, addrsize);
+   route->sourcemask = r_next->sourcemask;
route->iface = iface;
vlist_add(>host_routes, >node, route);
 
-- 
2.33.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH 2/2] interface-ip: use metric when looking for a route

2021-10-26 Thread luizluca
From: Luiz Angelo Daros de Luca 

When there were multiple routes with the same target but different
metrics, __find_ip_route_target was returning the first one,
independently of the metric.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 interface-ip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/interface-ip.c b/interface-ip.c
index 7c60fec..cecfb6d 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -234,7 +234,9 @@ __find_ip_route_target(struct interface_ip_settings *ip, 
union if_addr *a,
if (route->flags & DEVROUTE_TABLE)
continue;
 
-   if (!*res || route->mask > (*res)->mask)
+   if (!*res || route->mask > (*res)->mask ||
+   ((route->mask == (*res)->mask) && (route->flags & 
DEVROUTE_METRIC)
+&& (route->metric < (*res)->metric)))
*res = route;
}
 }
-- 
2.33.1


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v3 4/4] base-files: add sysupgrade -k to save list of pkgs

2018-08-17 Thread luizluca
From: Luiz Angelo Daros de Luca 

When '-k' is used, sysupgrade inserts into backup a new file
/etc/backup/installed_packages.txt which contains pkgname and origin (rom,
overlay, unknown) without touching rootfs.

It's maily used to reinstall all extra packages:

 # opkg update
 # grep "\toverlay" /etc/backup/installed_packages.txt | cut -f1 | xargs -r 
opkg install
 # rm /etc/backup/installed_packages.txt

Signed-off-by: Luiz Angelo Daros de Luca 
---
 package/base-files/files/sbin/sysupgrade | 36 +++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/package/base-files/files/sbin/sysupgrade 
b/package/base-files/files/sbin/sysupgrade
index ca02577c26..cb3b2918c5 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -11,6 +11,7 @@ export SAVE_CONFIG=1
 export SAVE_OVERLAY=0
 export SAVE_OVERLAY_PATH=
 export SAVE_PARTITIONS=1
+export SAVE_INSTALLED_PKGS=0
 export SKIP_UNCHANGED=0
 export CONF_IMAGE=
 export CONF_BACKUP_LIST=0
@@ -20,6 +21,7 @@ export NEED_IMAGE=
 export HELP=0
 export FORCE=0
 export TEST=0
+export UMOUNT_ETCBACKUP_DIR=0
 
 # parse options
 while [ -n "$1" ]; do
@@ -31,6 +33,7 @@ while [ -n "$1" ]; do
-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
-p) export SAVE_PARTITIONS=0;;
+   -k) export SAVE_INSTALLED_PKGS=1;;
-u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; 
shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; 
shift;;
@@ -50,13 +53,15 @@ done
 
 export CONFFILES=/tmp/sysupgrade.conffiles
 export CONF_TAR=/tmp/sysupgrade.tgz
+export ETCBACKUP_DIR=/etc/backup
+export INSTALLED_PACKAGES=${ETCBACKUP_DIR}/installed_packages.txt
 
 IMAGE="$1"
 
 [ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] 
&& {
cat <...] 
-   $0 [-q] [-i] [-c] [-u] [-o]  
+   $0 [-q] [-i] [-c] [-u] [-o] [-k]  
 
 upgrade-option:
-f   restore configuration from .tar.gz (file or url)
@@ -67,6 +72,8 @@ upgrade-option:
-u   skip from backup files that are equals to those in /rom
-n   do not save configuration over reflash
-p   do not attempt to restore the partition table after flash.
+   -k   include in backup a list of current installed packages at
+$INSTALLED_PACKAGES
-T | --test
 Verify image and config .tar.gz but do not actually flash.
-F | --force
@@ -174,6 +181,7 @@ add_overlayfiles() {
-e '\,^/etc/board.json$,d' \
-e '\,/[^/]*-opkg$,d' \
-e '\,^/etc/urandom.seed$,d' \
+   -e "\,^$INSTALLED_PACKAGES$,d" \
-e '\,^/usr/lib/opkg/.*,d' \
) | grep -v -x -F -f $packagesfiles > "$file"
 
@@ -218,6 +226,27 @@ do_save_conffiles() {
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
ask_bool 0 "Edit config file list" && vi "$CONFFILES"
 
+   if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
+   echo "${INSTALLED_PACKAGES}" >> "$CONFFILES"
+   mkdir -p "$ETCBACKUP_DIR"
+   # Avoid touching filesystem on each backup
+   RAMFS="$(mktemp -d -t sysupgrade.XX)"
+   mkdir -p "$RAMFS/upper" "$RAMFS/work"
+   mount -t overlay overlay -o 
lowerdir=$ETCBACKUP_DIR,upperdir=$RAMFS/upper,workdir=$RAMFS/work 
$ETCBACKUP_DIR &&
+   UMOUNT_ETCBACKUP_DIR=1 || {
+   echo "Cannot mount '$ETCBACKUP_DIR' as tmpfs to 
avoid touching disk while saving the list of installed packages." >&2
+   ask_bool 0 "Abort" && exit
+   }
+
+   # Format: pkg-name{rom,overlay,unkown}
+   # rom is used for pkgs in /rom, even if updated later
+   find /usr/lib/opkg/info -name "*.control" \( \
+   \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
+   \( -exec test -f /overlay/upper/{} \; -exec echo {} 
overlay \; \) -o \
+   \( -exec echo {} unknown \; \) \
+   \) | sed -e 's,.*/,,;s/\.control /\t/' > 
${INSTALLED_PACKAGES}
+   fi
+
v "Saving config files..."
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
@@ -227,11 +256,16 @@ do_save_conffiles() {
exit 1
fi
 
+   [ "$UMOUNT_ETCBACKUP_DIR" -eq 1 ] && {
+   umount "$ETCBACKUP_DIR"
+   rm -rf "$RAMFS"
+   }
rm -f "$CONFFILES"
 }
 
 if [ $CONF_BACKUP_LIST -eq 1 ]; then
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
+   [ "$SAVE_INSTALLED_PKGS" -eq 1 ] && echo ${INSTALLED_PACKAGES} >> 
"$CONFFILES"
cat 

[OpenWrt-Devel] [PATCH v3 3/4] base-files: add sysupgrade -o to save all overlay files

2018-08-17 Thread luizluca
From: Luiz Angelo Daros de Luca 

Add sysupgrade '-o' option in order to include all overlay files in
backup, except for those that are from packages but including files
listed in conffiles, sysupgrade.conf or /lib/upgrade/keep.d.

With '-u' option, it will skip files equals to /rom and conffiles that
were not changed.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 package/base-files/files/sbin/sysupgrade | 52 ++--
 1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade 
b/package/base-files/files/sbin/sysupgrade
index 45378d7266..ca02577c26 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -9,6 +9,7 @@ export INTERACTIVE=0
 export VERBOSE=1
 export SAVE_CONFIG=1
 export SAVE_OVERLAY=0
+export SAVE_OVERLAY_PATH=
 export SAVE_PARTITIONS=1
 export SKIP_UNCHANGED=0
 export CONF_IMAGE=
@@ -27,7 +28,8 @@ while [ -n "$1" ]; do
-v) export VERBOSE="$(($VERBOSE + 1))";;
-q) export VERBOSE="$(($VERBOSE - 1))";;
-n) export SAVE_CONFIG=0;;
-   -c) export SAVE_OVERLAY=1;;
+   -c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
+   -o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
-p) export SAVE_PARTITIONS=0;;
-u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; 
shift;;
@@ -54,12 +56,14 @@ IMAGE="$1"
 [ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] 
&& {
cat <...] 
-   $0 [-q] [-i] [-c] [-u]  
+   $0 [-q] [-i] [-c] [-u] [-o]  
 
 upgrade-option:
-f   restore configuration from .tar.gz (file or url)
-i   interactive mode
-c   attempt to preserve all changed files in /etc/
+   -o   attempt to preserve all changed files in /, exept those
+from packages but including changed confs.
-u   skip from backup files that are equals to those in /rom
-n   do not save configuration over reflash
-p   do not attempt to restore the partition table after flash.
@@ -129,12 +133,52 @@ add_conffiles() {
 
 add_overlayfiles() {
local file="$1"
-   ( cd /overlay/upper/; find ./etc \( -type f -o -type l \) $find_filter 
| sed \
+
+   local packagesfiles=$1.packagesfiles
+   touch "$packagesfiles"
+
+   if [ "$SAVE_OVERLAY_PATH" = / ]; then
+   local conffiles=$1.conffiles
+   local keepfiles=$1.keepfiles
+
+   list_conffiles | cut -f2 -d ' ' | sort -u > "$conffiles"
+
+   # backup files from /etc/sysupgrade.conf and 
/lib/upgrade/keep.d, but
+   # ignore those aready controlled by opkg conffiles
+   find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
+   /etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) 
\
+   \( -type f -o -type l \) 2>/dev/null | sort -u |
+   grep -h -v -x -F -f $conffiles > "$keepfiles"
+
+   # backup conffiles, but only those changed if '-u'
+   [ $SKIP_UNCHANGED = 1 ] &&
+   list_changed_conffiles | sort -u > "$conffiles"
+
+   # do not backup files from packages, except those listed
+   # in conffiles and keep.d
+   {
+   find /usr/lib/opkg/info -type f -name "*.list" -exec 
cat {} \;
+   find /usr/lib/opkg/info -type f -name "*.control" -exec 
sed \
+   -ne '/^Alternatives/{s/^Alternatives: //;s/, 
/\n/g;p}' {} \; |
+   cut -f2 -d:
+   } |  grep -v -x -F -f $conffiles |
+grep -v -x -F -f $keepfiles | sort -u > "$packagesfiles"
+   rm -f "$keepfiles" "$conffiles"
+   fi
+
+   # busybox grep bug when file is empty
+   [ -s "$packagesfiles" ] || echo > $packagesfiles
+
+   ( cd /overlay/upper/; find .$SAVE_OVERLAY_PATH \( -type f -o -type l \) 
$find_filter | sed \
-e 's,^\.,,' \
-e '\,^/etc/board.json$,d' \
-e '\,/[^/]*-opkg$,d' \
-e '\,^/etc/urandom.seed$,d' \
-   )> "$file"
+   -e '\,^/usr/lib/opkg/.*,d' \
+   ) | grep -v -x -F -f $packagesfiles > "$file"
+
+   rm -f "$packagesfiles"
+
return 0
 }
 
-- 
2.18.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v3 2/4] base-files: add sysupgrade -u to skip unchanged files

2018-08-17 Thread luizluca
From: Luiz Angelo Daros de Luca 

With '-u', for a file /aaa/bbb/ccc enlisted for backup,
it will only get into backup if /rom/aaa/bbb/ccc does not
exist or /aaa/bbb/ccc is different from /rom/aaa/bbb/ccc.

It also works with '-c', but only effective for files touched
but not modified.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 package/base-files/files/sbin/sysupgrade | 27 +---
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade 
b/package/base-files/files/sbin/sysupgrade
index 22e233033a..45378d7266 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -10,6 +10,7 @@ export VERBOSE=1
 export SAVE_CONFIG=1
 export SAVE_OVERLAY=0
 export SAVE_PARTITIONS=1
+export SKIP_UNCHANGED=0
 export CONF_IMAGE=
 export CONF_BACKUP_LIST=0
 export CONF_BACKUP=
@@ -28,6 +29,7 @@ while [ -n "$1" ]; do
-n) export SAVE_CONFIG=0;;
-c) export SAVE_OVERLAY=1;;
-p) export SAVE_PARTITIONS=0;;
+   -u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; 
shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; 
shift;;
-l|--list-backup) export CONF_BACKUP_LIST=1;;
@@ -52,12 +54,13 @@ IMAGE="$1"
 [ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] 
&& {
cat <...] 
-   $0 [-q] [-i] [-c]  
+   $0 [-q] [-i] [-c] [-u]  
 
 upgrade-option:
-f   restore configuration from .tar.gz (file or url)
-i   interactive mode
-c   attempt to preserve all changed files in /etc/
+   -u   skip from backup files that are equals to those in /rom
-n   do not save configuration over reflash
-p   do not attempt to restore the partition table after flash.
-T | --test
@@ -119,20 +122,19 @@ add_conffiles() {
local file="$1"
( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
-   -type f -o -type l 2>/dev/null;
+   \( -type f -o -type l \) $find_filter 2>/dev/null;
  list_changed_conffiles ) | sort -u > "$file"
return 0
 }
 
 add_overlayfiles() {
local file="$1"
-   find /overlay/upper/etc/ -type f -o -type l | sed \
-   -e 's,^/overlay\/upper/,/,' \
-   -e '\,/META_[a-zA-Z0-9]*$,d' \
-   -e '\,/functions.sh$,d' \
+   ( cd /overlay/upper/; find ./etc \( -type f -o -type l \) $find_filter 
| sed \
+   -e 's,^\.,,' \
+   -e '\,^/etc/board.json$,d' \
-e '\,/[^/]*-opkg$,d' \
-   -e '\,/etc/urandom.seed$,d' \
-   > "$file"
+   -e '\,^/etc/urandom.seed$,d' \
+   )> "$file"
return 0
 }
 
@@ -149,6 +151,15 @@ else
sysupgrade_init_conffiles="add_conffiles"
 fi
 
+find_filter=""
+if [ $SKIP_UNCHANGED = 1 ]; then
+   [ ! -d /rom/ ] && {
+   echo "'/rom/' is required by '-u'"
+   exit 1
+   }
+   find_filter='( ( -exec test -e /rom/{} ; -exec cmp -s /{} /rom/{} ; ) 
-o -print )'
+fi
+
 include /lib/upgrade
 
 do_save_conffiles() {
-- 
2.18.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v3 1/4] base-files: minor cleanups on sysupgrade

2018-08-17 Thread luizluca
From: Luiz Angelo Daros de Luca 

Renamed add_uci_conffiles to add_conffiles as it includes
any conffiles listed, not only UCI ones.

Make do_save_conffiles arg mandatory

Allow other options after -l (like -c)

Do not use stdout for error messages (fixes backup to stdout)

Signed-off-by: Luiz Angelo Daros de Luca 
---
 package/base-files/files/sbin/sysupgrade | 33 
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade 
b/package/base-files/files/sbin/sysupgrade
index 3cebfb68e0..22e233033a 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -30,13 +30,13 @@ while [ -n "$1" ]; do
-p) export SAVE_PARTITIONS=0;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; 
shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; 
shift;;
-   -l|--list-backup) export CONF_BACKUP_LIST=1; break;;
+   -l|--list-backup) export CONF_BACKUP_LIST=1;;
-f) export CONF_IMAGE="$2"; shift;;
-F|--force) export FORCE=1;;
-T|--test) export TEST=1;;
-h|--help) export HELP=1; break;;
-*)
-   echo "Invalid option: $1"
+   echo "Invalid option: $1" >&2
exit 1
;;
*) break;;
@@ -49,10 +49,10 @@ export CONF_TAR=/tmp/sysupgrade.tgz
 
 IMAGE="$1"
 
-[ -z "$IMAGE" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
+[ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] 
&& {
cat <...] 
-   $0 [-q] [-i]  
+   $0 [-q] [-i] [-c]  
 
 upgrade-option:
-f   restore configuration from .tar.gz (file or url)
@@ -115,7 +115,7 @@ list_changed_conffiles() {
done
 }
 
-add_uci_conffiles() {
+add_conffiles() {
local file="$1"
( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
@@ -131,6 +131,7 @@ add_overlayfiles() {
-e '\,/META_[a-zA-Z0-9]*$,d' \
-e '\,/functions.sh$,d' \
-e '\,/[^/]*-opkg$,d' \
+   -e '\,/etc/urandom.seed$,d' \
> "$file"
return 0
 }
@@ -140,21 +141,21 @@ sysupgrade_image_check="fwtool_check_signature 
fwtool_check_image platform_check
 
 if [ $SAVE_OVERLAY = 1 ]; then
[ ! -d /overlay/upper/etc ] && {
-   echo "Cannot find '/overlay/upper/etc', required for '-c'"
+   echo "Cannot find '/overlay/upper/etc', required for '-c'" >&2
exit 1
}
sysupgrade_init_conffiles="add_overlayfiles"
 else
-   sysupgrade_init_conffiles="add_uci_conffiles"
+   sysupgrade_init_conffiles="add_conffiles"
 fi
 
 include /lib/upgrade
 
 do_save_conffiles() {
-   local conf_tar="${1:-$CONF_TAR}"
+   local conf_tar="$1"
 
[ -z "$(rootfs_type)" ] && {
-   echo "Cannot save config while running from ramdisk."
+   echo "Cannot save config while running from ramdisk." >&2
ask_bool 0 "Abort" && exit
rm -f "$conf_tar"
return 0
@@ -188,7 +189,7 @@ fi
 
 if [ -n "$CONF_RESTORE" ]; then
if [ "$CONF_RESTORE" != "-" ] && [ ! -f "$CONF_RESTORE" ]; then
-   echo "Backup archive '$CONF_RESTORE' not found."
+   echo "Backup archive '$CONF_RESTORE' not found." >&2
exit 1
fi
 
@@ -198,7 +199,7 @@ if [ -n "$CONF_RESTORE" ]; then
 fi
 
 type platform_check_image >/dev/null 2>/dev/null || {
-   echo "Firmware upgrade is not implemented for this platform."
+   echo "Firmware upgrade is not implemented for this platform." >&2
exit 1
 }
 
@@ -213,7 +214,7 @@ IMAGE="$(readlink -f "$IMAGE")"
 
 case "$IMAGE" in
'')
-   echo "Image file not found."
+   echo "Image file not found." >&2
exit 1
;;
/tmp/*) ;;
@@ -230,10 +231,10 @@ export ARGC=1
 for check in $sysupgrade_image_check; do
( $check "$IMAGE" ) || {
if [ $FORCE -eq 1 ]; then
-   echo "Image check '$check' failed but --force given - 
will update anyway!"
+   echo "Image check '$check' failed but --force given - 
will update anyway!" >&2
break
else
-   echo "Image check '$check' failed."
+   echo "Image check '$check' failed." >&2
exit 1
fi
}
@@ -244,14 +245,14 @@ if [ -n "$CONF_IMAGE" ]; then
# .gz files
1f8b) ;;
*)
-   echo "Invalid config file. Please use only .tar.gz 
files"
+   echo "Invalid config file. Please use only .tar.gz 
files" >&2

[OpenWrt-Devel] [PATCH v3 0/4] base-files: add new backup options

2018-08-17 Thread luizluca
From: Luiz Angelo Daros de Luca 

Today, every file listed in /etc/sysupgrade.conf, /etc/config,
marked as changed conffile and others will be in backup. Some of
these files from previous OpenWrt version might break something.
/etc/profile is a good example of what should not be in backup if
unchanged. Also, any conffile that has a new required parameter
might break after restore.

When the user changes a file, it is expected that he/she knows that
he/she is doing. The problem is when OpenWrt replaces a file with one
from a previous version that the user might not even know that it exists.

The new '-u' option asks backup to (oportunisticly) skip any file that
is equals to /rom. If a system does not have /rom, it simply does
nothing. /rom does not need to actually be squashfs. If the user is using
ext4, he/she could simply copy files into /rom before the first change
is made. IMHO, it should even be the default behavior.

A backup might also miss important files for the user. The user must
insert every single file needed in /etc/sysupgrade.conf in order to get
it into a backup. However, it is easy to simply miss one. '-c' option
does try to save everything, but limited to /etc, probably to skip code
files. Saving /overlay also works but only when restoring to an
identical OpenWrt version. The new '-o' is equivalent to saving
/overlay, but it skips any files that came from a package, except those
marked as a changed config file, sysupgrade.conf or /lib/upgrade/keep.d.
It does work with '-u', skipping files touched but reverted to the
original state.

After the user seeded a new OpenWrt with a backup generated with '-o'
and '-u', the next natural step is to reinstall all previously installed
packages. '-k' adds a file into the backup containing the list of
installed packages and also its origin (rom or overlay). It is a one-line
script to reinstall them all.

My normal upgrade procedure is:

 # sysupgrade -o -k -u openwrt-new-version.img
 # 
 # opkg update
 # grep "\toverlay" /etc/backup/installed_packages.txt | cut -f1 | xargs -r 
opkg install
 # rm /etc/backup/installed_packages.txt
 # reboot

Those options could be used by Luci, exposed to user during an upgrade.
The (re)installation step could even become automatic (on demand) or
offered to the user when Luci detects /etc/backup/installed_packages.txt
presence.

Changes from previous versions:

V2-V3:
* Rename installed packages file to /etc/backup/installed_packages.txt
* Avoid touching flash by using overlay instead of tar append hack
* Also consider Alternatives as package files
* Skip /etc/backup/installed_packages.txt from a backup without '-k'
* Send sysupgrade msgs to stderr

V1-V2:
* Ignore unchanged files from /rom became an option ('-u')
* Add '-o' to save all /overlay, except software files
* Add '-k' to save installed packages
* Minor cleanups

References:

V3
* https://github.com/luizluca/openwrt/tree/better-backups-v3

V2
* https://github.com/luizluca/openwrt/tree/better-backups-v2
* https://patchwork.ozlabs.org/cover/895208/

V1
* https://github.com/luizluca/openwrt/tree/better-backups-v1
* https://lists.openwrt.org/pipermail/openwrt-devel/2017-November/009892.html

Luiz Angelo Daros de Luca (4):
  base-files: minor cleanups on sysupgrade
  base-files: add sysupgrade -u to skip unchanged files
  base-files: add sysupgrade -o to save all overlay files
  base-files: add sysupgrade -k to save list of pkgs

 package/base-files/files/sbin/sysupgrade | 136 +++
 1 file changed, 113 insertions(+), 23 deletions(-)

-- 
2.18.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] Compile xen-pci-frontend as module

2014-05-27 Thread luizluca
From: Luiz Angelo Daros de Luca luizl...@gmail.com

There is a package for /drivers/pci/xen-pcifront.ko (kmod-xen-pcidev)
However, the kernel module was defined to be built-in and not loadable.
(Is there any special reason?)
This patch changes (back?) the xen-pcifront.ko to loadable module

Signed-off-by: Luiz Angelo Daros de Luca luizl...@gmail.com
---
 target/linux/x86/xen_domu/config-3.10 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/linux/x86/xen_domu/config-3.10 
b/target/linux/x86/xen_domu/config-3.10
index 4b7c80f..cf4a8d5 100644
--- a/target/linux/x86/xen_domu/config-3.10
+++ b/target/linux/x86/xen_domu/config-3.10
@@ -69,7 +69,7 @@ CONFIG_XEN_GRANT_DEV_ALLOC=m
 CONFIG_XEN_HAVE_PVMMU=y
 CONFIG_XEN_MAX_DOMAIN_MEMORY=64
 # CONFIG_XEN_NETDEV_FRONTEND is not set
-CONFIG_XEN_PCIDEV_FRONTEND=y
+CONFIG_XEN_PCIDEV_FRONTEND=m
 CONFIG_XEN_PRIVCMD=m
 # CONFIG_XEN_PRIVILEGED_GUEST is not set
 CONFIG_XEN_PVHVM=y
-- 
1.8.4.5
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] [comgt] add support for defining dial number in config file

2014-03-17 Thread luizluca
From: Luiz Angelo Daros de Luca luizl...@gmail.com

Signed-off-by: Luiz Angelo Daros de Luca luizl...@gmail.com
---
 package/network/utils/comgt/Makefile  | 2 +-
 package/network/utils/comgt/files/3g.chat | 2 +-
 package/network/utils/comgt/files/3g.sh   | 9 -
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/package/network/utils/comgt/Makefile 
b/package/network/utils/comgt/Makefile
index 5324903..89a21be 100644
--- a/package/network/utils/comgt/Makefile
+++ b/package/network/utils/comgt/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=comgt
 PKG_VERSION:=0.32
-PKG_RELEASE:=21
+PKG_RELEASE:=22
 
 PKG_SOURCE:=$(PKG_NAME).$(PKG_VERSION).tgz
 PKG_SOURCE_URL:=@SF/comgt
diff --git a/package/network/utils/comgt/files/3g.chat 
b/package/network/utils/comgt/files/3g.chat
index a1fa2a0..6656240 100644
--- a/package/network/utils/comgt/files/3g.chat
+++ b/package/network/utils/comgt/files/3g.chat
@@ -8,5 +8,5 @@ OK  ATE1
 OK  'AT+CGDCONT=1,IP,$USE_APN'
 SAY Calling UMTS/GPRS
 TIMEOUT 30
-OK  ATD*99***1#
+OK  ATD$DIALNUMBER
 CONNECT ' '
diff --git a/package/network/utils/comgt/files/3g.sh 
b/package/network/utils/comgt/files/3g.sh
index 2dc719b..deca2c9 100644
--- a/package/network/utils/comgt/files/3g.sh
+++ b/package/network/utils/comgt/files/3g.sh
@@ -13,6 +13,7 @@ proto_3g_init_config() {
proto_config_add_string apn
proto_config_add_string service
proto_config_add_string pincode
+   proto_config_add_string dialnumber
 }
 
 proto_3g_setup() {
@@ -23,6 +24,7 @@ proto_3g_setup() {
json_get_var apn apn
json_get_var service service
json_get_var pincode pincode
+   json_get_var dialnumber dialnumber
 
[ -e $device ] || {
proto_set_available $interface 0
@@ -74,10 +76,15 @@ proto_3g_setup() {
[ -n $SIERRA ]  {
gcom -d $device -s /etc/gcom/getcarrier.gcom 
|| return 1
}
+
+   if [ -z $dialnumber ]; then
+   dialnumber=*99***1#
+   fi
+
;;
esac
 
-   connect=${apn:+USE_APN=$apn }/usr/sbin/chat -t5 -v -E -f $chat
+   connect=${apn:+USE_APN=$apn }DIALNUMBER=$dialnumber /usr/sbin/chat -t5 
-v -E -f $chat
ppp_generic_setup $interface \
noaccomp \
nopcomp \
-- 
1.8.4.5
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] [comgt] add support for defining dial number in config file

2014-03-17 Thread luizluca
Some telcoms requires specific dial number in order to connect 3g dongles.
Currently, the only possible way is to edit /etc/chatscripts/3g.chat, which
is not very userfriendly.

This patch adds the optional option dialnumber to /etc/config/network for 3g.
If provided, it will replace the default dial number *99***1#.

If merged, I'll update wiki doc ASAP.

The next step will be to add this field to Luci interface.

---
     Luiz Angelo Daros de Luca, Me.
            luizl...@gmail.com
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel