[lib] mes_lookup string lookup table argument should be marked const

2008-08-14 Stephen Hemminger <stephen.hemminger@vyatta.com>

	* lib/log.{c,h}: struct message argument should point to const
	* */*.c: adjust to suit,

Signed-off-by: Paul Jakma <paul@quagga.net>
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 71f3ec7..5dbd487 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -314,6 +314,11 @@
   sockopt_reuseaddr (peer->fd);
   sockopt_reuseport (peer->fd);
   
+#ifdef IPTOS_PREC_INTERNETCONTROL
+  if (sockunion_family (&peer->su) == AF_INET)
+    setsockopt_ipv4_tos (peer->fd, IPTOS_PREC_INTERNETCONTROL);
+#endif
+
   if (peer->password)
     bgp_md5_set_connect (peer->fd, &peer->su, peer->password);
 
@@ -402,6 +407,11 @@
       sockopt_reuseaddr (sock);
       sockopt_reuseport (sock);
       
+#ifdef IPTOS_PREC_INTERNETCONTROL
+      if (ainfo->ai_family == AF_INET)
+	setsockopt_ipv4_tos (sock, IPTOS_PREC_INTERNETCONTROL);
+#endif
+
       if (bgpd_privs.change (ZPRIVS_RAISE) )
         zlog_err ("bgp_socket: could not raise privs");
 
@@ -454,6 +464,10 @@
   sockopt_reuseaddr (sock);
   sockopt_reuseport (sock);
 
+#ifdef IPTOS_PREC_INTERNETCONTROL
+  setsockopt_ipv4_tos (sock, IPTOS_PREC_INTERNETCONTROL);
+#endif
+
   memset (&sin, 0, sizeof (struct sockaddr_in));
 
   sin.sin_family = AF_INET;
diff --git a/lib/log.c b/lib/log.c
index ce00bfb..677cf9a 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -740,9 +740,9 @@
 
 /* Message lookup function. */
 const char *
-lookup (struct message *mes, int key)
+lookup (const struct message *mes, int key)
 {
-  struct message *pnt;
+  const struct message *pnt;
 
   for (pnt = mes; pnt->key != 0; pnt++) 
     if (pnt->key == key) 
diff --git a/lib/log.h b/lib/log.h
index 7432b25..777fd77 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -144,7 +144,7 @@
 /* For hackey massage lookup and check */
 #define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)")
 
-extern const char *lookup (struct message *, int);
+extern const char *lookup (const struct message *, int);
 extern const char *mes_lookup (struct message *meslist, 
                                int max, int index,
                                const char *no_item);
diff --git a/lib/memory.c b/lib/memory.c
index 9ed5e10..28b3d89 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -33,7 +33,7 @@
 static void alloc_dec (int);
 static void log_memstats(int log_priority);
 
-static struct message mstr [] =
+static const struct message mstr [] =
 {
   { MTYPE_THREAD, "thread" },
   { MTYPE_THREAD_MASTER, "thread_master" },
diff --git a/lib/sockopt.c b/lib/sockopt.c
index a2038a5..2f01199 100644
--- a/lib/sockopt.c
+++ b/lib/sockopt.c
@@ -343,6 +343,19 @@
 }
 
 int
+setsockopt_ipv4_tos(int sock, int tos)
+{
+  int ret;
+
+  ret = setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (tos));
+  if (ret < 0)
+    zlog_warn ("Can't set IP_TOS option for fd %d to %#x: %s",
+	       sock, tos, safe_strerror(errno));
+  return ret;
+}
+
+
+int
 setsockopt_ifindex (int af, int sock, int val)
 {
   int ret = -1;
diff --git a/lib/sockopt.h b/lib/sockopt.h
index 9538279..cb05c6f 100644
--- a/lib/sockopt.h
+++ b/lib/sockopt.h
@@ -89,6 +89,7 @@
 			             unsigned int ifindex
 					 /* optional: if non-zero, may be used
 					 	instead of if_addr */);
+extern int setsockopt_ipv4_tos(int sock, int tos);
 
 /* Ask for, and get, ifindex, by whatever method is supported. */
 extern int setsockopt_ifindex (int, int, int);
diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c
index d5bf749..89ff203 100644
--- a/ospfd/ospf_network.c
+++ b/ospfd/ospf_network.c
@@ -165,11 +165,7 @@
 ospf_sock_init (void)
 {
   int ospf_sock;
-  /*
-   * XXX warning: unused variable `tos'
-   * tos should be ifdefed similarly to usage
-   */
-  int ret, tos, hincl = 1;
+  int ret, hincl = 1;
 
   if ( ospfd_privs.change (ZPRIVS_RAISE) )
     zlog_err ("ospf_sock_init: could not raise privs, %s",
@@ -201,10 +197,7 @@
 #elif defined (IPTOS_PREC_INTERNETCONTROL)
 #warning "IP_HDRINCL not available on this system"
 #warning "using IPTOS_PREC_INTERNETCONTROL"
-  /* Set precedence field. */
-  tos = IPTOS_PREC_INTERNETCONTROL;
-  ret = setsockopt (ospf_sock, IPPROTO_IP, IP_TOS,
-		    (char *) &tos, sizeof (int));
+  ret = setsockopt_ipv4_tos(ospf_sock, IPTOS_PREC_INTERNETCONTROL);
   if (ret < 0)
     {
       int save_errno = errno;
diff --git a/ripd/ripd.c b/ripd/ripd.c
index 62d8691..2525679 100644
--- a/ripd/ripd.c
+++ b/ripd/ripd.c
@@ -76,7 +76,7 @@
 };
 
 /* RIP command strings. */
-struct message rip_msg[] = 
+static const struct message rip_msg[] =
 {
   {RIP_REQUEST,    "REQUEST"},
   {RIP_RESPONSE,   "RESPONSE"},
@@ -84,6 +84,7 @@
   {RIP_TRACEOFF,   "TRACEOFF"},
   {RIP_POLL,       "POLL"},
   {RIP_POLL_ENTRY, "POLL ENTRY"},
+  {0, NULL},
 };
 
 /* Utility function to set boradcast option to the socket. */
@@ -3508,7 +3509,7 @@
   struct listnode *node;
   struct interface *ifp;
   struct rip_interface *ri;
-  extern struct message ri_version_msg[];
+  extern const struct message ri_version_msg[];
   const char *send_version;
   const char *receive_version;
 
diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c
index 2e04b03..e77b9b7 100644
--- a/zebra/kernel_socket.c
+++ b/zebra/kernel_socket.c
@@ -126,7 +126,7 @@
       (LEN) = 0; \
     }
 /* Routing socket message types. */
-struct message rtm_type_str[] =
+const struct message rtm_type_str[] =
 {
   {RTM_ADD,      "RTM_ADD"},
   {RTM_DELETE,   "RTM_DELETE"},
diff --git a/zebra/kernel_socket.h b/zebra/kernel_socket.h
index 8f8a207..e9558ad 100644
--- a/zebra/kernel_socket.h
+++ b/zebra/kernel_socket.h
@@ -28,6 +28,6 @@
 extern int ifm_read (struct if_msghdr *);
 extern int rtm_write (int, union sockunion *, union sockunion *,
                       union sockunion *, unsigned int, int, int);
-extern struct message rtm_type_str[];
+extern const struct message rtm_type_str[];
 
 #endif /* __ZEBRA_KERNEL_SOCKET_H */
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 0a6b8dd..395f1ca 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -52,7 +52,7 @@
 } netlink      = { -1, 0, {0}, "netlink-listen"},     /* kernel messages */
   netlink_cmd  = { -1, 0, {0}, "netlink-cmd"};        /* command channel */
 
-static struct message nlmsg_str[] = {
+static const struct message nlmsg_str[] = {
   {RTM_NEWROUTE, "RTM_NEWROUTE"},
   {RTM_DELROUTE, "RTM_DELROUTE"},
   {RTM_GETROUTE, "RTM_GETROUTE"},
@@ -805,7 +805,7 @@
   return 0;
 }
 
-struct message rtproto_str[] = {
+static const struct message rtproto_str[] = {
   {RTPROT_REDIRECT, "redirect"},
   {RTPROT_KERNEL,   "kernel"},
   {RTPROT_BOOT,     "boot"},