Merged,
Maxim.

On 12/18/2015 20:45, Balasubramanian Manoharan wrote:
Reviewed-by: Balasubramanian Manoharan <[email protected]>

On 18/12/15 6:58 PM, Matias Elo wrote:
Fixes netmap "cast discards '__attribute__((const))'" build
error. Define pkt_addr as const as classifier operations
should be read-only to packet data.

Signed-off-by: Matias Elo <[email protected]>
---
.../include/odp_classification_inlines.h | 73 ++++++++++++----------
  .../include/odp_classification_internal.h          | 14 ++---
  .../linux-generic/include/odp_packet_io_internal.h |  2 +-
  platform/linux-generic/odp_classification.c        | 30 ++++-----
  platform/linux-generic/pktio/netmap.c              |  2 +-
  platform/linux-generic/pktio/pktio_common.c        |  4 +-
  6 files changed, 66 insertions(+), 59 deletions(-)

diff --git a/platform/linux-generic/include/odp_classification_inlines.h b/platform/linux-generic/include/odp_classification_inlines.h
index 7f13530..e9739aa 100644
--- a/platform/linux-generic/include/odp_classification_inlines.h
+++ b/platform/linux-generic/include/odp_classification_inlines.h
@@ -39,15 +39,16 @@ static inline int verify_pmr_packet_len(odp_packet_hdr_t *pkt_hdr,
        return 0;
  }
-static inline int verify_pmr_ip_proto(uint8_t *pkt_addr,
+
+static inline int verify_pmr_ip_proto(const uint8_t *pkt_addr,
                        odp_packet_hdr_t *pkt_hdr,
                        pmr_term_value_t *term_value)
  {
-    odph_ipv4hdr_t *ip;
+    const odph_ipv4hdr_t *ip;
      uint8_t proto;
      if (!pkt_hdr->input_flags.ipv4)
          return 0;
-    ip = (odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset);
+    ip = (const odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset);
      proto = ip->proto;
      if (term_value->val == (proto & term_value->mask))
          return 1;
@@ -55,15 +56,15 @@ static inline int verify_pmr_ip_proto(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_ipv4_saddr(uint8_t *pkt_addr,
+static inline int verify_pmr_ipv4_saddr(const uint8_t *pkt_addr,
                      odp_packet_hdr_t *pkt_hdr,
                      pmr_term_value_t *term_value)
  {
-    odph_ipv4hdr_t *ip;
+    const odph_ipv4hdr_t *ip;
      uint32_t ipaddr;
      if (!pkt_hdr->input_flags.ipv4)
          return 0;
-    ip = (odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset);
+    ip = (const odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset);
      ipaddr = odp_be_to_cpu_32(ip->src_addr);
      if (term_value->val == (ipaddr & term_value->mask))
          return 1;
@@ -71,15 +72,15 @@ static inline int verify_pmr_ipv4_saddr(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_ipv4_daddr(uint8_t *pkt_addr,
+static inline int verify_pmr_ipv4_daddr(const uint8_t *pkt_addr,
                      odp_packet_hdr_t *pkt_hdr,
                      pmr_term_value_t *term_value)
  {
-    odph_ipv4hdr_t *ip;
+    const odph_ipv4hdr_t *ip;
      uint32_t ipaddr;
      if (!pkt_hdr->input_flags.ipv4)
          return 0;
-    ip = (odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset);
+    ip = (const odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset);
      ipaddr = odp_be_to_cpu_32(ip->dst_addr);
      if (term_value->val == (ipaddr & term_value->mask))
          return 1;
@@ -87,15 +88,15 @@ static inline int verify_pmr_ipv4_daddr(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_tcp_sport(uint8_t *pkt_addr,
+static inline int verify_pmr_tcp_sport(const uint8_t *pkt_addr,
                         odp_packet_hdr_t *pkt_hdr,
                         pmr_term_value_t *term_value)
  {
      uint16_t sport;
-    odph_tcphdr_t *tcp;
+    const odph_tcphdr_t *tcp;
      if (!pkt_hdr->input_flags.tcp)
          return 0;
-    tcp = (odph_tcphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
+    tcp = (const odph_tcphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
      sport = odp_be_to_cpu_16(tcp->src_port);
      if (term_value->val == (sport & term_value->mask))
          return 1;
@@ -103,15 +104,15 @@ static inline int verify_pmr_tcp_sport(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_tcp_dport(uint8_t *pkt_addr,
+static inline int verify_pmr_tcp_dport(const uint8_t *pkt_addr,
                         odp_packet_hdr_t *pkt_hdr,
                         pmr_term_value_t *term_value)
  {
      uint16_t dport;
-    odph_tcphdr_t *tcp;
+    const odph_tcphdr_t *tcp;
      if (!pkt_hdr->input_flags.tcp)
          return 0;
-    tcp = (odph_tcphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
+    tcp = (const odph_tcphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
      dport = odp_be_to_cpu_16(tcp->dst_port);
      if (term_value->val == (dport & term_value->mask))
          return 1;
@@ -119,30 +120,32 @@ static inline int verify_pmr_tcp_dport(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_udp_dport(uint8_t *pkt_addr,
+static inline int verify_pmr_udp_dport(const uint8_t *pkt_addr,
                         odp_packet_hdr_t *pkt_hdr,
                         pmr_term_value_t *term_value)
  {
      uint16_t dport;
-    odph_udphdr_t *udp;
+    const odph_udphdr_t *udp;
      if (!pkt_hdr->input_flags.udp)
          return 0;
-    udp = (odph_udphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
+    udp = (const odph_udphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
      dport = odp_be_to_cpu_16(udp->dst_port);
      if (term_value->val == (dport & term_value->mask))
              return 1;
        return 0;
  }
-static inline int verify_pmr_udp_sport(uint8_t *pkt_addr,
+
+static inline int verify_pmr_udp_sport(const uint8_t *pkt_addr,
                         odp_packet_hdr_t *pkt_hdr,
                         pmr_term_value_t *term_value)
  {
      uint16_t sport;
-    odph_udphdr_t *udp;
+    const odph_udphdr_t *udp;
+
      if (!pkt_hdr->input_flags.udp)
          return 0;
-    udp = (odph_udphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
+    udp = (const odph_udphdr_t *)(pkt_addr + pkt_hdr->l4_offset);
      sport = odp_be_to_cpu_16(udp->src_port);
      if (term_value->val == (sport & term_value->mask))
          return 1;
@@ -150,7 +153,7 @@ static inline int verify_pmr_udp_sport(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_dmac(uint8_t *pkt_addr ODP_UNUSED,
+static inline int verify_pmr_dmac(const uint8_t *pkt_addr ODP_UNUSED,
                    odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                    pmr_term_value_t *term_value ODP_UNUSED)
  {
@@ -158,28 +161,31 @@ static inline int verify_pmr_dmac(uint8_t *pkt_addr ODP_UNUSED,
      return 0;
  }
  -static inline int verify_pmr_ipv6_saddr(uint8_t *pkt_addr ODP_UNUSED,
+static inline int verify_pmr_ipv6_saddr(const uint8_t *pkt_addr ODP_UNUSED,
                      odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                      pmr_term_value_t *term_value ODP_UNUSED)
  {
      ODP_UNIMPLEMENTED();
      return 0;
  }
-static inline int verify_pmr_ipv6_daddr(uint8_t *pkt_addr ODP_UNUSED,
+
+static inline int verify_pmr_ipv6_daddr(const uint8_t *pkt_addr ODP_UNUSED,
                      odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                      pmr_term_value_t *term_value ODP_UNUSED)
  {
      ODP_UNIMPLEMENTED();
      return 0;
  }
-static inline int verify_pmr_vlan_id_0(uint8_t *pkt_addr ODP_UNUSED,
+
+static inline int verify_pmr_vlan_id_0(const uint8_t *pkt_addr ODP_UNUSED,
                         odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                         pmr_term_value_t *term_value ODP_UNUSED)
  {
      ODP_UNIMPLEMENTED();
      return 0;
  }
-static inline int verify_pmr_vlan_id_x(uint8_t *pkt_addr ODP_UNUSED,
+
+static inline int verify_pmr_vlan_id_x(const uint8_t *pkt_addr ODP_UNUSED,
                         odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                         pmr_term_value_t *term_value ODP_UNUSED)
  {
@@ -187,7 +193,7 @@ static inline int verify_pmr_vlan_id_x(uint8_t *pkt_addr ODP_UNUSED,
      return 0;
  }
  -static inline int verify_pmr_ipsec_spi(uint8_t *pkt_addr,
+static inline int verify_pmr_ipsec_spi(const uint8_t *pkt_addr,
                         odp_packet_hdr_t *pkt_hdr,
                         pmr_term_value_t *term_value)
  {
@@ -199,11 +205,11 @@ static inline int verify_pmr_ipsec_spi(uint8_t *pkt_addr,
      pkt_addr += pkt_hdr->l4_offset;
        if (pkt_hdr->l4_protocol == ODPH_IPPROTO_AH) {
-        odph_ahhdr_t *ahhdr = (odph_ahhdr_t *)pkt_addr;
+        const odph_ahhdr_t *ahhdr = (const odph_ahhdr_t *)pkt_addr;
            spi = odp_be_to_cpu_32(ahhdr->spi);
      } else if (pkt_hdr->l4_protocol == ODPH_IPPROTO_ESP) {
-        odph_esphdr_t *esphdr = (odph_esphdr_t *)pkt_addr;
+        const odph_esphdr_t *esphdr = (const odph_esphdr_t *)pkt_addr;
            spi = odp_be_to_cpu_32(esphdr->spi);
      } else {
@@ -216,7 +222,7 @@ static inline int verify_pmr_ipsec_spi(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_ld_vni(uint8_t *pkt_addr ODP_UNUSED,
+static inline int verify_pmr_ld_vni(const uint8_t *pkt_addr ODP_UNUSED,
                      odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                      pmr_term_value_t *term_value ODP_UNUSED)
  {
@@ -224,7 +230,7 @@ static inline int verify_pmr_ld_vni(uint8_t *pkt_addr ODP_UNUSED,
      return 0;
  }
  -static inline int verify_pmr_custom_frame(uint8_t *pkt_addr,
+static inline int verify_pmr_custom_frame(const uint8_t *pkt_addr,
                        odp_packet_hdr_t *pkt_hdr,
                        pmr_term_value_t *term_value)
  {
@@ -244,14 +250,15 @@ static inline int verify_pmr_custom_frame(uint8_t *pkt_addr,
      return 0;
  }
  -static inline int verify_pmr_eth_type_0(uint8_t *pkt_addr ODP_UNUSED,
+static inline int verify_pmr_eth_type_0(const uint8_t *pkt_addr ODP_UNUSED,
                      odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                      pmr_term_value_t *term_value ODP_UNUSED)
  {
      ODP_UNIMPLEMENTED();
      return 0;
  }
-static inline int verify_pmr_eth_type_x(uint8_t *pkt_addr ODP_UNUSED,
+
+static inline int verify_pmr_eth_type_x(const uint8_t *pkt_addr ODP_UNUSED,
                      odp_packet_hdr_t *pkt_hdr ODP_UNUSED,
                      pmr_term_value_t *term_value ODP_UNUSED)
  {
diff --git a/platform/linux-generic/include/odp_classification_internal.h b/platform/linux-generic/include/odp_classification_internal.h
index 45af14d..1e8f291 100644
--- a/platform/linux-generic/include/odp_classification_internal.h
+++ b/platform/linux-generic/include/odp_classification_internal.h
@@ -40,8 +40,8 @@ with the PKTIO interface.
  Returns the default cos if the packet does not match any PMR
  Returns the error_cos if the packet has an error
  **/
-cos_t *pktio_select_cos(pktio_entry_t *pktio, uint8_t *pkt_addr,
-               odp_packet_hdr_t *pkt_hdr);
+cos_t *pktio_select_cos(pktio_entry_t *pktio, const uint8_t *pkt_addr,
+            odp_packet_hdr_t *pkt_hdr);
    /**
  @internal
@@ -51,7 +51,7 @@ Select a CoS for the given Packet based on QoS values
  This function returns the COS object matching the L2 and L3 QoS
  based on the l3_preference value of the pktio
  **/
-cos_t *match_qos_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
+cos_t *match_qos_cos(pktio_entry_t *entry, const uint8_t *pkt_addr,
               odp_packet_hdr_t *hdr);
  /**
  Packet Classifier
@@ -87,7 +87,7 @@ This function gets called recursively to check the chained PMR Term value
  with the packet.
    **/
-cos_t *match_pmr_cos(cos_t *cos, uint8_t *pkt_addr, pmr_t *pmr,
+cos_t *match_pmr_cos(cos_t *cos, const uint8_t *pkt_addr, pmr_t *pmr,
               odp_packet_hdr_t *hdr);
  /**
  @internal
@@ -95,7 +95,7 @@ CoS associated with L3 QoS value
    This function returns the CoS associated with L3 QoS value
  **/
-cos_t *match_qos_l3_cos(pmr_l3_cos_t *l3_cos, uint8_t *pkt_addr,
+cos_t *match_qos_l3_cos(pmr_l3_cos_t *l3_cos, const uint8_t *pkt_addr,
              odp_packet_hdr_t *hdr);
    /**
@@ -104,7 +104,7 @@ CoS associated with L2 QoS value
    This function returns the CoS associated with L2 QoS value
  **/
-cos_t *match_qos_l2_cos(pmr_l2_cos_t *l2_cos, uint8_t *pkt_addr,
+cos_t *match_qos_l2_cos(pmr_l2_cos_t *l2_cos, const uint8_t *pkt_addr,
              odp_packet_hdr_t *hdr);
  /**
  @internal
@@ -174,7 +174,7 @@ This function goes through each PMR_TERM value in pmr_t structure and calls verification function for each term.Returns 1 if PMR matches or 0
  Otherwise.
  **/
-int verify_pmr(pmr_t *pmr, uint8_t *pkt_addr, odp_packet_hdr_t *pkt_hdr); +int verify_pmr(pmr_t *pmr, const uint8_t *pkt_addr, odp_packet_hdr_t *pkt_hdr);
    #ifdef __cplusplus
  }
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index 61bedc9..e15c6af 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -154,7 +154,7 @@ typedef struct pktio_if_ops {
                odp_packet_t packets[], int num);
  } pktio_if_ops_t;
  -int _odp_packet_cls_enq(pktio_entry_t *pktio_entry, uint8_t *base,
+int _odp_packet_cls_enq(pktio_entry_t *pktio_entry, const uint8_t *base,
              uint16_t buf_len, odp_packet_t *pkt_ret);
    extern void *pktio_entry_ptr[];
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index b1f51af..d7e2efb 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -700,7 +700,7 @@ odp_pool_t odp_cls_cos_pool(odp_cos_t cos_id)
      return cos->s.pool->s.pool_hdl;
  }
-int verify_pmr(pmr_t *pmr, uint8_t *pkt_addr, odp_packet_hdr_t *pkt_hdr) +int verify_pmr(pmr_t *pmr, const uint8_t *pkt_addr, odp_packet_hdr_t *pkt_hdr)
  {
      int pmr_failure = 0;
      int num_pmr;
@@ -818,7 +818,7 @@ int verify_pmr(pmr_t *pmr, uint8_t *pkt_addr, odp_packet_hdr_t *pkt_hdr)
      return true;
  }
  -cos_t *match_pmr_cos(cos_t *cos, uint8_t *pkt_addr, pmr_t *pmr,
+cos_t *match_pmr_cos(cos_t *cos, const uint8_t *pkt_addr, pmr_t *pmr,
               odp_packet_hdr_t *hdr)
  {
      cos_t *retcos = NULL;
@@ -916,8 +916,8 @@ int packet_classifier(odp_pktio_t pktio, odp_packet_t pkt)
      return _odp_packet_classifier(entry, pkt);
  }
  -cos_t *pktio_select_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
-               odp_packet_hdr_t *pkt_hdr)
+cos_t *pktio_select_cos(pktio_entry_t *entry, const uint8_t *pkt_addr,
+            odp_packet_hdr_t *pkt_hdr)
  {
      pmr_t *pmr;
      cos_t *cos;
@@ -949,20 +949,20 @@ cos_t *pktio_select_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
      return cls->default_cos;
  }
  -cos_t *match_qos_l3_cos(pmr_l3_cos_t *l3_cos, uint8_t *pkt_addr,
+cos_t *match_qos_l3_cos(pmr_l3_cos_t *l3_cos, const uint8_t *pkt_addr,
              odp_packet_hdr_t *hdr)
  {
      uint8_t dscp;
      cos_t *cos = NULL;
-    odph_ipv4hdr_t *ipv4;
-    odph_ipv6hdr_t *ipv6;
+    const odph_ipv4hdr_t *ipv4;
+    const odph_ipv6hdr_t *ipv6;
        if (hdr->input_flags.l3 && hdr->input_flags.ipv4) {
-        ipv4 = (odph_ipv4hdr_t *)(pkt_addr + hdr->l3_offset);
+        ipv4 = (const odph_ipv4hdr_t *)(pkt_addr + hdr->l3_offset);
          dscp = ODPH_IPV4HDR_DSCP(ipv4->tos);
          cos = l3_cos->cos[dscp];
      } else if (hdr->input_flags.l3 && hdr->input_flags.ipv6) {
-        ipv6 = (odph_ipv6hdr_t *)(pkt_addr + hdr->l3_offset);
+        ipv6 = (const odph_ipv6hdr_t *)(pkt_addr + hdr->l3_offset);
          dscp = ODPH_IPV6HDR_DSCP(ipv6->ver_tc_flow);
          cos = l3_cos->cos[dscp];
      }
@@ -970,18 +970,18 @@ cos_t *match_qos_l3_cos(pmr_l3_cos_t *l3_cos, uint8_t *pkt_addr,
      return cos;
  }
  -cos_t *match_qos_l2_cos(pmr_l2_cos_t *l2_cos, uint8_t *pkt_addr,
+cos_t *match_qos_l2_cos(pmr_l2_cos_t *l2_cos, const uint8_t *pkt_addr,
              odp_packet_hdr_t *hdr)
  {
      cos_t *cos = NULL;
-    odph_ethhdr_t *eth;
-    odph_vlanhdr_t *vlan;
+    const odph_ethhdr_t *eth;
+    const odph_vlanhdr_t *vlan;
      uint16_t qos;
        if (hdr->input_flags.l2 && hdr->input_flags.vlan &&
          hdr->input_flags.eth) {
-        eth = (odph_ethhdr_t *)(pkt_addr + hdr->l2_offset);
-        vlan = (odph_vlanhdr_t *)(&eth->type);
+        eth = (const odph_ethhdr_t *)(pkt_addr + hdr->l2_offset);
+        vlan = (const odph_vlanhdr_t *)(&eth->type);
          qos = odp_be_to_cpu_16(vlan->tci);
          qos = ((qos >> 13) & 0x07);
          cos = l2_cos->cos[qos];
@@ -989,7 +989,7 @@ cos_t *match_qos_l2_cos(pmr_l2_cos_t *l2_cos, uint8_t *pkt_addr,
      return cos;
  }
  -cos_t *match_qos_cos(pktio_entry_t *entry, uint8_t *pkt_addr,
+cos_t *match_qos_cos(pktio_entry_t *entry, const uint8_t *pkt_addr,
               odp_packet_hdr_t *hdr)
  {
      classifier_t *cls = &entry->s.cls;
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index d2a4626..4bc51fd 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -567,7 +567,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry,
      }
        if (pktio_cls_enabled(pktio_entry)) {
-        ret = _odp_packet_cls_enq(pktio_entry, (uint8_t *)buf,
+        ret = _odp_packet_cls_enq(pktio_entry, (const uint8_t *)buf,
                        len, pkt_out);
          if (ret)
              return 0;
diff --git a/platform/linux-generic/pktio/pktio_common.c b/platform/linux-generic/pktio/pktio_common.c
index 1fb10a0..05200ba 100644
--- a/platform/linux-generic/pktio/pktio_common.c
+++ b/platform/linux-generic/pktio/pktio_common.c
@@ -13,7 +13,7 @@
  #include <odp_classification_internal.h>
    int _odp_packet_cls_enq(pktio_entry_t *pktio_entry,
-            uint8_t *base, uint16_t buf_len,
+            const uint8_t *base, uint16_t buf_len,
              odp_packet_t *pkt_ret)
  {
      cos_t *cos;
@@ -25,7 +25,7 @@ int _odp_packet_cls_enq(pktio_entry_t *pktio_entry,
      packet_parse_reset(&pkt_hdr);
        _odp_cls_parse(&pkt_hdr, base);
-    cos = pktio_select_cos(pktio_entry, (uint8_t *)base, &pkt_hdr);
+    cos = pktio_select_cos(pktio_entry, base, &pkt_hdr);
      pool = cos->s.pool->s.pool_hdl;
        /* if No CoS found then drop the packet */

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to