1  /* Reduced from haproxy's src/ssl_sample.c  */
       2  
       3  union sample_value {
       4    long long int sint;
       5    /* [...snip...]  */
       6  };
       7  
       8  struct sample_data {
       9   int type;
      10   union sample_value u;
      11  };
      12  
      13  enum {
      14    /* [...snip...]  */
      15   SMP_T_BOOL,
      16    /* [...snip...]  */
      17  };
      18  struct sample {
      19   unsigned int flags;
      20   struct sample_data data;
      21    /* [...snip...]  */
      22   struct session *sess;
      23   struct stream *strm;
      24    /* [...snip...]  */
      25  };
      26  struct arg {
      27    /* [...snip...]  */
      28  };
      29  enum obj_type {
      30   OBJ_TYPE_NONE = 0,
      31    /* [...snip...]  */
      32   OBJ_TYPE_CONN,
      33    /* [...snip...]  */
      34   OBJ_TYPE_CHECK,
      35   OBJ_TYPE_ENTRIES
      36  };
      37  enum {
      38    /* [...snip...]  */
      39   CO_FL_EARLY_SSL_HS = 0x00004000,
      40   CO_FL_EARLY_DATA = 0x00008000,
      41    /* [...snip...]  */
      42   CO_FL_SSL_WAIT_HS = 0x08000000,
      43    /* [...snip...]  */
      44  };
      45  struct connection {
      46   enum obj_type obj_type;
      47   unsigned char err_code;
      48    /* [...snip...]  */
      49   unsigned int flags;
      50    /* [...snip...]  */
      51  };
      52  
      53  static inline enum obj_type obj_type(const enum obj_type *t)
      54  {
      55   if (!t || *t >= OBJ_TYPE_ENTRIES)
      56    return OBJ_TYPE_NONE;
      57   return *t;
      58  }
      59  static inline struct connection *__objt_conn(enum obj_type *t)
      60  {
      61   return ((struct connection *)(((void *)(t)) - ((long)&((struct connection *)0)->obj_type)));
      62  }
      63  static inline struct connection *objt_conn(enum obj_type *t)
      64  {
      65   if (!t || *t != OBJ_TYPE_CONN)
      66     return ((void *)0);
      67   return __objt_conn(t);
      68  }
      69  struct session {
      70    /* [...snip...]  */
      71   enum obj_type *origin;
      72    /* [...snip...]  */
      73  };
      74  typedef struct ssl_st SSL;
      75  SSL *ssl_sock_get_ssl_object(struct connection *conn);
      76  
      77  /*****************************************************************************/
      78  
      79  int
      80  smp_fetch_ssl_fc_has_early(const struct arg *args, struct sample *smp, const char *kw, void *private)
      81  {
      82   SSL *ssl;
      83   struct connection *conn;
      84  
      85   conn = objt_conn(smp->sess->origin);
      86   ssl = ssl_sock_get_ssl_object(conn);
      87   if (!ssl)
      88    return 0;
      89  
      90   smp->flags = 0;
      91   smp->data.type = SMP_T_BOOL;
      92   smp->data.u.sint = ((conn->flags & CO_FL_EARLY_DATA) && /* { dg-bogus "dereference of NULL 'conn'" "PR analyzer/108251" { xfail *-*-*} } */
      93       (conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_SSL_WAIT_HS))) ? 1 : 0;
      94  
      95   return 1;
      96  }