Re: [MOD] STR #4106: "ipp" tries to query a CUPS server with lots of SNMP requests

Michael Sweet <[email protected]> Sat, 15 Sep 2012 11:30:49 -0700 (PDT)
Newsgroups gmane.comp.printing.cups.bugs
Message-ID <[email protected]>
DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR Closed w/Resolution]

Fixed in Subversion repository.

The change adds a new "snmp" option for all of the network backends. I was
also able to key off the normal Bonjour shared printer URI path ("/cups" on
the end) to add the "snmp" option to the resolved URI so that Bonjour
shared printers do not use SNMP.

Link: http://www.cups.org/str.php?L4106
Version: 1.4.7
Fix Version: 1.7-current

_______________________________________________
cups-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/cups-bugs
str4106.patch (text/plain, 10.6 KB)
Index: backend/lpd.c
===================================================================
--- backend/lpd.c	(revision 10596)
+++ backend/lpd.c	(working copy)
@@ -126,6 +126,7 @@
   int		port;			/* Port number */
   char		portname[256];		/* Port name (string) */
   http_addrlist_t *addrlist;		/* List of addresses for printer */
+  int		snmp_enabled = 1;	/* Is SNMP enabled? */
   int		snmp_fd;		/* SNMP socket */
   int		fd;			/* Print file */
   int		status;			/* Status of LPD job */
@@ -356,7 +357,8 @@
 	*/

         if (!value[0] || !_cups_strcasecmp(value, "on") ||
-	    !_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true") ||
+	    !_cups_strcasecmp(value, "yes") ||
+	    !_cups_strcasecmp(value, "true") ||
 	    !_cups_strcasecmp(value, "rfc1179"))
 	  reserve = RESERVE_RFC1179;
 	else if (!_cups_strcasecmp(value, "any"))
@@ -371,7 +373,8 @@
 	*/

         manual_copies = !value[0] || !_cups_strcasecmp(value, "on") ||
-	 		!_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true");
+	 		!_cups_strcasecmp(value, "yes") ||
+	 		!_cups_strcasecmp(value, "true");
       }
       else if (!_cups_strcasecmp(name, "sanitize_title"))
       {
@@ -380,8 +383,19 @@
 	*/

         sanitize_title = !value[0] || !_cups_strcasecmp(value, "on") ||
-	 		 !_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true");
+	 		 !_cups_strcasecmp(value, "yes") ||
+	 		 !_cups_strcasecmp(value, "true");
       }
+      else if (!_cups_strcasecmp(name, "snmp"))
+      {
+        /*
+         * Enable/disable SNMP stuff...
+         */
+
+         snmp_enabled = !value[0] || !_cups_strcasecmp(value, "on") ||
+                        _cups_strcasecmp(value, "yes") ||
+                        _cups_strcasecmp(value, "true");
+      }
       else if (!_cups_strcasecmp(name, "timeout"))
       {
        /*
@@ -428,7 +442,10 @@
     }
   }

-  snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family);
+  if (snmp_enabled)
+    snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family);
+  else
+    snmp_fd = -1;

  /*
   * Wait for data from the filter...
Index: backend/ipp.c
===================================================================
--- backend/ipp.c	(revision 10603)
+++ backend/ipp.c	(working copy)
@@ -203,6 +203,7 @@
 		*value,			/* Value of option */
 		sep;			/* Separator character */
   http_addrlist_t *addrlist;		/* Address of printer */
+  int		snmp_enabled = 1;	/* Is SNMP enabled? */
   int		snmp_fd,		/* SNMP socket */
 		start_count,		/* Page count via SNMP at start */
 		page_count,		/* Page count via SNMP */
@@ -508,6 +509,16 @@
 			       value);
         }
       }
+      else if (!_cups_strcasecmp(name, "snmp"))
+      {
+        /*
+         * Enable/disable SNMP stuff...
+         */
+
+         snmp_enabled = !value[0] || !_cups_strcasecmp(value, "on") ||
+                        _cups_strcasecmp(value, "yes") ||
+                        _cups_strcasecmp(value, "true");
+      }
       else if (!_cups_strcasecmp(name, "version"))
       {
         if (!strcmp(value, "1.0"))
@@ -659,11 +670,14 @@
   * See if the printer supports SNMP...
   */

-  if ((snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family)) >= 0)
-  {
+  if (snmp_enabled)
+    snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family);
+  else
+    snmp_fd = -1;
+
+  if (snmp_fd >= 0)
     have_supplies = !backendSNMPSupplies(snmp_fd, &(addrlist->addr),
                                          &start_count, NULL);
-  }
   else
     have_supplies = start_count = 0;

Index: backend/socket.c
===================================================================
--- backend/socket.c	(revision 10596)
+++ backend/socket.c	(working copy)
@@ -87,6 +87,7 @@
   http_addrlist_t *addrlist,		/* Address list */
 		*addr;			/* Connected address */
   char		addrname[256];		/* Address name */
+  int		snmp_enabled = 1;	/* Is SNMP enabled? */
   int		snmp_fd,		/* SNMP socket */
 		start_count,		/* Page count via SNMP at start */
 		page_count,		/* Page count via SNMP */
@@ -246,6 +247,16 @@
         waiteof = !value[0] || !_cups_strcasecmp(value, "on") ||
 		  !_cups_strcasecmp(value, "yes") || !_cups_strcasecmp(value, "true");
       }
+      else if (!_cups_strcasecmp(name, "snmp"))
+      {
+        /*
+         * Enable/disable SNMP stuff...
+         */
+
+         snmp_enabled = !value[0] || !_cups_strcasecmp(value, "on") ||
+                        _cups_strcasecmp(value, "yes") ||
+                        _cups_strcasecmp(value, "true");
+      }
       else if (!_cups_strcasecmp(name, "contimeout"))
       {
        /*
@@ -286,11 +297,14 @@
   * See if the printer supports SNMP...
   */

-  if ((snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family)) >= 0)
-  {
+  if (snmp_enabled)
+    snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family);
+  else
+    snmp_fd = -1;
+
+  if (snmp_fd >= 0)
     have_supplies = !backendSNMPSupplies(snmp_fd, &(addrlist->addr),
                                          &start_count, NULL);
-  }
   else
     have_supplies = start_count = 0;

Index: doc/help/network.html
===================================================================
--- doc/help/network.html	(revision 10596)
+++ doc/help/network.html	(working copy)
@@ -93,16 +93,22 @@

 <PRE>
 socket://<i>ip-address-or-hostname</i>
-socket://<i>ip-address-or-hostname</i>/?waiteof=false
+socket://<i>ip-address-or-hostname</i>/?option=value
+socket://<i>ip-address-or-hostname</i>/?option=value&option=value
 socket://<i>ip-address-or-hostname</i>:<i>port-number</i>
-socket://<i>ip-address-or-hostname</i>:<i>port-number</i>/?waiteof=false
+socket://<i>ip-address-or-hostname</i>:<i>port-number</i>/?option=value
+socket://<i>ip-address-or-hostname</i>:<i>port-number</i>/?option=value&option=value
 </PRE>

+<P>The "contimeout" option controls the number of seconds that the backend will wait to obtain a connection to the printer. The default is 1 week.</P>
+
+<P>The "snmp" option controls whether the <tt>socket</tt> backend queries for supply and page count information via SNMP.</P>
+
 <P>The "waiteof" option controls whether the <tt>socket</tt> backend waits for the printer to complete the printing of the job. The default is to wait.</P>

 <H3><A NAME="IPP">Internet Printing Protocol (IPP)</A></H3>

-<P>IPP is the only protocol that CUPS supports natively and is supported by some network printers and print servers. However, since many printers do not implement IPP properly, only use IPP when the vendor actually documents official support for it. IPP printing normally happens over port 631 and uses the <tt>http</tt> and <tt>ipp</tt> URI schemes:</P>
+<P>IPP is the only protocol that CUPS supports natively and is supported by some network printers and print servers. However, since many printers do not implement IPP properly, only use IPP when the vendor actually documents official support for it. IPP printing normally happens over port 631 and uses the <tt>http</tt>, <tt>ipp</tt>, and <tt>ipps</tt> URI schemes:</P>

 <PRE>
 http://<i>ip-address-or-hostname</i>:<i>port-number</i>/<i>resource</i>
@@ -114,6 +120,12 @@
 ipp://<i>ip-address-or-hostname</i>:<i>port-number</i>/<i>resource</i>
 ipp://<i>ip-address-or-hostname</i>:<i>port-number</i>/<i>resource</i>?<i>option=value</i>
 ipp://<i>ip-address-or-hostname</i>:<i>port-number</i>/<i>resource</i>?<i>option=value&option=value</i>
+ipps://<i>ip-address-or-hostname</i>/<i>resource</i>
+ipps://<i>ip-address-or-hostname</i>/<i>resource</i>?<i>option=value</i>
+ipps://<i>ip-address-or-hostname</i>/<i>resource</i>?<i>option=value&option=value</i>
+ipps://<i>ip-address-or-hostname</i>:<i>port-number</i>/<i>resource</i>
+ipps://<i>ip-address-or-hostname</i>:<i>port-number</i>/<i>resource</i>?<i>option=value</i>
+ipps://<i>ip-address-or-hostname</i>:<i>port-number</i>/<i>resource</i>?<i>option=value&option=value</i>
 </PRE>

 <P>The <tt>ipp</tt> backend supports many options, which are summarized in <A HREF="#TABLE2">Table 2</A>.</P>
@@ -148,16 +160,20 @@
 	<TD>Specifies that the connection to the IPP server should be encrypted using TLS.</TD>
 </TR>
 <TR>
+	<TD><TT>snmp=false</TT></TD>
+	<TD>Specifies that SNMP supply and page count queries should not be performed.</TD>
+</TR>
+<TR>
 	<TD><TT>version=1.0</TT></TD>
-	<TD>Specifies that version 1.0 of the IPP protocol should be used instead of the default version 1.1.</TD>
+	<TD>Specifies that version 1.0 of the IPP protocol should be used instead of the default version 2.0.</TD>
 </TR>
 <TR>
-	<TD><TT>version=2.0</TT></TD>
-	<TD>Specifies that version 2.0 of the IPP protocol should be used instead of the default version 1.1.</TD>
+	<TD><TT>version=1.1</TT></TD>
+	<TD>Specifies that version 1.1 of the IPP protocol should be used instead of the default version 2.0.</TD>
 </TR>
 <TR>
 	<TD><TT>version=2.1</TT></TD>
-	<TD>Specifies that version 2.1 of the IPP protocol should be used instead of the default version 1.1.</TD>
+	<TD>Specifies that version 2.1 of the IPP protocol should be used instead of the default version 2.0.</TD>
 </TR>
 <TR>
 	<TD><TT>waitjob=false</TT></TD>
@@ -267,6 +283,10 @@
 	<TD>Specifies that the job title string should be restricted to ASCII characters.</TD>
 </TR>
 <TR>
+	<TD><TT>snmp=false</TT></TD>
+	<TD>Specifies that SNMP supply and page count queries should not be performed.</TD>
+</TR>
+<TR>
 	<TD><TT>timeout=<I>seconds</I></TT></TD>
 	<TD>Specifies the number of seconds to wait for LPD commands to complete.</TD>
 </TR>
Index: cups/http-support.c
===================================================================
--- cups/http-support.c	(revision 10596)
+++ cups/http-support.c	(working copy)
@@ -82,6 +82,7 @@
   char			*buffer;	/* Pointer to buffer */
   size_t		bufsize;	/* Size of buffer */
   int			options;	/* Options passed to _httpResolveURI */
+  const char		*resource;	/* Resource from URI */
 } _http_uribuf_t;


@@ -1523,6 +1524,7 @@
     uribuf.buffer   = resolved_uri;
     uribuf.bufsize  = resolved_size;
     uribuf.options  = options;
+    uribuf.resource = resource;

     resolved_uri[0] = '\0';

@@ -2064,8 +2066,14 @@
   * Assemble the final device URI...
   */

-  httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, uribuf->bufsize, scheme,
-                  NULL, hostTarget, ntohs(port), resource);
+  if ((!strcmp(scheme, "ipp") || !strcmp(scheme, "ipps")) &&
+      !strcmp(uribuf->resource, "/cups"))
+    httpAssembleURIf(HTTP_URI_CODING_ALL, uribuf->buffer, uribuf->bufsize,
+                     scheme, NULL, hostTarget, ntohs(port), "%s?snmp=false",
+                     resource);
+  else
+    httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, uribuf->bufsize,
+                    scheme, NULL, hostTarget, ntohs(port), resource);

   DEBUG_printf(("8http_resolve_cb: Resolved URI is \"%s\"...", uribuf->buffer));
 }