0008-ifconfig-Apply-interface-flags-correctly.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. From 31537b75b74ece069617b255f05d229a00943b28 Mon Sep 17 00:00:00 2001
  2. From: Mats Erik Andersson <gnu@gisladisker.se>
  3. Date: Sat, 1 Aug 2015 20:38:55 +0200
  4. Subject: [PATCH 08/60] ifconfig: Apply interface flags correctly.
  5. Changes of interface flags could be suppressed when
  6. an address assignment was requested at the same time.
  7. Suppress also printout when properties are changed.
  8. Reported by Hans-Peter Budek.
  9. ---
  10. ChangeLog | 29 +++++++++++++++++++++++++++++
  11. ifconfig/options.c | 27 ++++++++++++++++++++++++---
  12. ifconfig/options.h | 6 ++----
  13. 3 files changed, 55 insertions(+), 7 deletions(-)
  14. diff --git a/ChangeLog b/ChangeLog
  15. index 2f664b8d..557b7a9c 100644
  16. --- a/ChangeLog
  17. +++ b/ChangeLog
  18. @@ -1,3 +1,32 @@
  19. +2015-08-01 Mats Erik Andersson <gnu@gisladisker.se>
  20. +
  21. + ifconfig: Apply flags correctly.
  22. + When finalizing actions, some flags could be forgotten.
  23. + In particular, the flag 'up' was ignored whenever an
  24. + address was assigned at the same time. This is related
  25. + to the fact that an invocation only effecting interface
  26. + flags, still resulted in a full printout if interface
  27. + status. This latter behaviour differs from all other
  28. + implementations and is rather annoying. The issue was
  29. + detected and reported by Hans-Peter Budek in
  30. + http://lists.gnu.org/archive/html/bug-inetutils/2015-07/msg00000.html
  31. +
  32. + * ifconfig/options.c (pending_setflags, pending_clrflags):
  33. + Define as static variables.
  34. + (pending_valid): New variable.
  35. + (argp_options) <message 'up'>: Delete the claim that 'up' be
  36. + a default action together with address.
  37. + (parse_opt_set_flag): When `ifp' exists, update `ifp->valid'
  38. + with IF_VALID_FLAGS. Otherwise, update `pending_valid'.
  39. + (parse_opt_finalize): If `ifp' exists and `pending_valid` is
  40. + set, then update `ifp->valid'. The update of `ifp->setflags'
  41. + and `ifp->clrflags' is performed independently of assigning
  42. + an output format, as the latter would cause a printout also
  43. + when only some flag is being altered.
  44. + * ifconfig/options.h (IF_VALID_FLAGS): New macro.
  45. + (IF_VALID_HWADDR): Updated value.
  46. + (pending_setflags. pending_clrflags): Removed declaration.
  47. +
  48. 2015-07-30 Mats Erik Andersson <gnu@gisladisker.se>
  49. ifconfig: A work-around specific to GNU/Hurd.
  50. diff --git a/ifconfig/options.c b/ifconfig/options.c
  51. index 30320622..484f2522 100644
  52. --- a/ifconfig/options.c
  53. +++ b/ifconfig/options.c
  54. @@ -49,8 +49,9 @@ int list_mode;
  55. int verbose;
  56. /* Flags asked for, possibly still pending application. */
  57. -int pending_setflags;
  58. -int pending_clrflags;
  59. +static int pending_setflags = 0;
  60. +static int pending_clrflags = 0;
  61. +static int pending_valid = 0;
  62. /* Array of all interfaces on the command line. */
  63. struct ifconfig *ifs;
  64. @@ -270,7 +271,7 @@ static struct argp_option argp_options[] = {
  65. { "format", FORMAT_OPTION, "FORMAT", 0,
  66. "select output format; set to `help' for info", GRP },
  67. { "up", UP_OPTION, NULL, 0,
  68. - "activate the interface (default if address is given)", GRP },
  69. + "activate the interface", GRP },
  70. { "down", DOWN_OPTION, NULL, 0,
  71. "shut the interface down", GRP },
  72. { "flags", 'F', "FLAG[,FLAG...]", 0,
  73. @@ -381,6 +382,11 @@ void
  74. parse_opt_set_flag (struct ifconfig *ifp _GL_UNUSED_PARAMETER,
  75. int flag, int rev)
  76. {
  77. + if (ifp)
  78. + ifp->valid |= IF_VALID_FLAGS;
  79. + else
  80. + pending_valid |= IF_VALID_FLAGS;
  81. +
  82. if (rev)
  83. {
  84. pending_clrflags |= flag;
  85. @@ -496,12 +502,27 @@ parse_opt_set_default_format_from_file (const char *file)
  86. void
  87. parse_opt_finalize (struct ifconfig *ifp)
  88. {
  89. + /* The flags `--up' and `--down' are allowed early. */
  90. + if (ifp && pending_valid)
  91. + {
  92. + ifp->valid |= pending_valid;
  93. + pending_valid = 0;
  94. + }
  95. +
  96. + /* Only the empty set of actions, i.e., only the interface name
  97. + * is present on the command line, merits printout of status.
  98. + */
  99. if (ifp && !ifp->valid)
  100. {
  101. ifp->valid = IF_VALID_FORMAT;
  102. ifp->format = default_format;
  103. + }
  104. +
  105. + if (ifp && (pending_setflags | pending_clrflags))
  106. + {
  107. ifp->setflags |= pending_setflags;
  108. ifp->clrflags |= pending_clrflags;
  109. + pending_setflags = pending_clrflags = 0;
  110. }
  111. }
  112. diff --git a/ifconfig/options.h b/ifconfig/options.h
  113. index 10528386..b3bfae43 100644
  114. --- a/ifconfig/options.h
  115. +++ b/ifconfig/options.h
  116. @@ -50,9 +50,10 @@ struct ifconfig
  117. int mtu;
  118. # define IF_VALID_METRIC 0x100
  119. int metric;
  120. +# define IF_VALID_FLAGS 0x200
  121. int setflags;
  122. int clrflags;
  123. -# define IF_VALID_HWADDR 0x200
  124. +# define IF_VALID_HWADDR 0x400
  125. char *hwaddr;
  126. };
  127. @@ -67,9 +68,6 @@ extern struct format formats[];
  128. extern int all_option;
  129. extern int ifs_cmdline;
  130. -extern int pending_setflags;
  131. -extern int pending_clrflags;
  132. -
  133. /* Array of interfaces mentioned on the command line. */
  134. extern struct ifconfig *ifs;
  135. extern int nifs;
  136. --
  137. 2.26.0.292.g33ef6b2f38